UrlUtils { public static String canonicalizeUrl(String url, String refer) { URL base; try { try { base = new URL(refer); } catch (MalformedURLException e) { URL abs = new URL(refer); return abs.toExternalForm(); } if (url.startsWith("?")) url = base.getPath() + url; URL abs = new URL(base, url); return abs.toExternalForm(); } catch (MalformedURLException e) { return ""; } }  static String canonicalizeUrl(String url, String refer); static String encodeIllegalCharacterInUrl(String url); static String fixIllegalCharacterInUrl(String url); static String getHost(String url); static String removeProtocol(String url); static String getDomain(String url); static String removePort(String domain); static List<Request> convertToRequests(Collection<String> urls); static List<String> convertToUrls(Collection<Request> requests); static String getCharset(String contentType);  }
@Test public void testFixRelativeUrl() { String absoluteUrl = UrlUtils.canonicalizeUrl("aa", "http: assertThat(absoluteUrl).isEqualTo("http: absoluteUrl = UrlUtils.canonicalizeUrl("../aa", "http: assertThat(absoluteUrl).isEqualTo("http: absoluteUrl = UrlUtils.canonicalizeUrl("../mshz", "http: assertThat(absoluteUrl).isEqualTo("http: absoluteUrl = UrlUtils.canonicalizeUrl("..aa", "http: assertThat(absoluteUrl).isEqualTo("http: absoluteUrl = UrlUtils.canonicalizeUrl("../../aa", "http: assertThat(absoluteUrl).isEqualTo("http: absoluteUrl = UrlUtils.canonicalizeUrl("../../aa", "http: assertThat(absoluteUrl).isEqualTo("http: }