@Test public void checkAllowed_allowPrivate() { UrlSanitizerUtils.checkAllowed("http: }
public static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate) { if (whitelist != null && !whitelist.isEmpty()) { if (whitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) { throw new UrlForbiddenException(); } } else if (!allowPrivate && UrlSanitizerUtils.isPrivate(url)) { throw new UrlForbiddenException(); } }
UrlSanitizerUtils { public static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate) { if (whitelist != null && !whitelist.isEmpty()) { if (whitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) { throw new UrlForbiddenException(); } } else if (!allowPrivate && UrlSanitizerUtils.isPrivate(url)) { throw new UrlForbiddenException(); } } }
UrlSanitizerUtils { public static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate) { if (whitelist != null && !whitelist.isEmpty()) { if (whitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) { throw new UrlForbiddenException(); } } else if (!allowPrivate && UrlSanitizerUtils.isPrivate(url)) { throw new UrlForbiddenException(); } }  }
UrlSanitizerUtils { public static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate) { if (whitelist != null && !whitelist.isEmpty()) { if (whitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) { throw new UrlForbiddenException(); } } else if (!allowPrivate && UrlSanitizerUtils.isPrivate(url)) { throw new UrlForbiddenException(); } }  static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate); static boolean isPrivate(String url); }
UrlSanitizerUtils { public static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate) { if (whitelist != null && !whitelist.isEmpty()) { if (whitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) { throw new UrlForbiddenException(); } } else if (!allowPrivate && UrlSanitizerUtils.isPrivate(url)) { throw new UrlForbiddenException(); } }  static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate); static boolean isPrivate(String url);  }