UriResolver { public URL resolveAgainstBaseUri(String uriString) throws MalformedURLException { URL resolvedUrl = null; uriString = uriString.trim(); uriString = UriEncodeUtil.encode(uriString); if (isLocalBaseUri) { if (!uriString.startsWith("file:")) { try { Path path = Paths.get(uriString); if (path.isAbsolute()) { resolvedUrl = path.toUri().toURL(); } } catch (Exception ignored) { } } } if (resolvedUrl == null) { resolvedUrl = new URL(baseUrl, uriString); } return resolvedUrl; } UriResolver(String baseUri); String getBaseUri(); URL resolveAgainstBaseUri(String uriString); boolean isLocalBaseUri();  }
@Test public void uriResolverTest17() throws MalformedURLException { String absolutePathRoot = Paths.get("").toAbsolutePath().getRoot().toUri().toURL().toString(); String absoluteBaseUri = absolutePathRoot + "test/fol ders/wi@th/diffe#rent/$characters/test/folder/index.html\t\t\t\t\t\t"; UriResolver resolver = new UriResolver(absoluteBaseUri); String malformedPath = absolutePathRoot + "test/fol%20ders/wi@th/diffe#rent/$characters/"; Assert.assertNotNull(malformedPath + "test/folder/innerTest", resolver.resolveAgainstBaseUri("innerTest").toExternalForm()); Assert.assertNotNull(malformedPath + "test/folder2/innerTest2", resolver.resolveAgainstBaseUri("../folder2/innerTest2").toExternalForm()); Assert.assertNotNull(malformedPath + "test/folder/folder2/innerTest2", resolver.resolveAgainstBaseUri("/folder2/innerTest2").toExternalForm()); Assert.assertNotNull(malformedPath + "test/folder/folder2/innerTest2", resolver.resolveAgainstBaseUri(" }
@Test public void singleQuoteRelativePath() throws MalformedURLException { String expectedUrl = "https: String baseUri = "https: String relativePath = "%D7%90%D7%91%D7%92'%D7%93"; UriResolver resolver = new UriResolver(baseUri); Assert.assertEquals(expectedUrl, resolver.resolveAgainstBaseUri(relativePath).toExternalForm()); }
@Test @Ignore("DEVSIX-2880: single quote character isn't encoded in Java and .NET 4.0, but it's encoded in .NETCoreApp 1.0" + " from single quote to %27") public void quoteInPercentsRelativePath() throws MalformedURLException { String expectedUrl = "https: String baseUri = "https: String relativePath = "%D7%90%D7%91%D7%92%27%D7%93"; UriResolver resolver = new UriResolver(baseUri); Assert.assertEquals(expectedUrl, resolver.resolveAgainstBaseUri(relativePath).toExternalForm()); }
@Test public void singleQuoteBasePath() throws MalformedURLException { String expectedUrl = "https: String baseUri = "https: String relativePath = "%D7%90%D7%91%D7%92%D7%93"; UriResolver resolver = new UriResolver(baseUri); Assert.assertEquals(expectedUrl, resolver.resolveAgainstBaseUri(relativePath).toExternalForm()); }
@Test @Ignore("DEVSIX-2880: single quote character isn't encoded in Java and .NET 4.0, but it's encoded in .NETCoreApp 1.0" + " from single quote to %27") public void quoteInPercentsBasePath() throws MalformedURLException { String expectedUrl = "https: String baseUri = "https: String relativePath = "%D7%90%D7%91%D7%92%D7%93"; UriResolver resolver = new UriResolver(baseUri); Assert.assertEquals(expectedUrl, resolver.resolveAgainstBaseUri(relativePath).toExternalForm()); }