Merge pull request #2392 from eclipse/jetty-9.4.x-issue-2387-uriutils-jarfile

Issue #2387 - fixing URIUtil.equalsIgnoreEncoding() with jar:file:// uris
This commit is contained in:
Joakim Erdfelt 2018-04-04 06:16:35 -05:00 committed by GitHub
commit 9147e408c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -1046,9 +1046,17 @@ public class URIUtil
if (uriB.getScheme()!=null)
return false;
}
else if (!uriA.getScheme().equals(uriB.getScheme()))
else if (!uriA.getScheme().equalsIgnoreCase(uriB.getScheme()))
return false;
if ("jar".equalsIgnoreCase(uriA.getScheme()))
{
// at this point we know that both uri's are "jar:"
URI uriAssp = URI.create(uriA.getSchemeSpecificPart());
URI uriBssp = URI.create(uriB.getSchemeSpecificPart());
return equalsIgnoreEncodings(uriAssp, uriBssp);
}
if (uriA.getAuthority()==null)
{
if (uriB.getAuthority()!=null)
@ -1057,7 +1065,7 @@ public class URIUtil
else if (!uriA.getAuthority().equals(uriB.getAuthority()))
return false;
return equalsIgnoreEncodings(uriA.getPath(),uriB.getPath());
return equalsIgnoreEncodings(uriA.getPath(), uriB.getPath());
}
/**

View File

@ -30,13 +30,12 @@ import java.nio.charset.StandardCharsets;
import org.junit.Test;
/* ------------------------------------------------------------ */
/** Util meta Tests.
*
/**
* URIUtil Tests.
*/
@SuppressWarnings("SpellCheckingInspection")
public class URIUtilTest
{
/* ------------------------------------------------------------ */
@Test
public void testEncodePath()
{
@ -66,7 +65,6 @@ public class URIUtilTest
assertEquals("test%3F%C3%B6%3F%C3%B6:%C3%9F", buf.toString());
}
/* ------------------------------------------------------------ */
@Test
public void testDecodePath()
{
@ -88,7 +86,6 @@ public class URIUtilTest
assertEquals(odd,URIUtil.decodePath("/%00/"));
}
/* ------------------------------------------------------------ */
@Test
public void testAddEncodedPaths()
{
@ -177,7 +174,7 @@ public class URIUtilTest
assertEquals("aaa;JS?A=1+/bbb", URIUtil.addEncodedPaths("aaa/;JS?A=1","/bbb"),"aaa/bbb;JS?A=1");
}
/* ------------------------------------------------------------ */
@Test
public void testAddDecodedPaths()
{
@ -249,7 +246,6 @@ public class URIUtilTest
}
/* ------------------------------------------------------------ */
@Test
public void testCompactPath()
{
@ -263,7 +259,6 @@ public class URIUtilTest
assertEquals("/foo/bar?a=b//c", URIUtil.compactPath("/foo///bar?a=b//c"));
}
/* ------------------------------------------------------------ */
@Test
public void testParentPath()
{
@ -275,7 +270,7 @@ public class URIUtilTest
assertEquals("parent null",null, URIUtil.parentPath(null));
}
/* ------------------------------------------------------------ */
@Test
public void testEqualsIgnoreEncoding()
{
@ -297,7 +292,18 @@ public class URIUtilTest
assertFalse(URIUtil.equalsIgnoreEncodings("/foo2fbar","/foo/bar"));
}
/* ------------------------------------------------------------ */
@Test
public void testEqualsIgnoreEncoding_JarFile()
{
URI uriA = URI.create("jar:file:/path/to/main.jar!/META-INF/versions/");
URI uriB = URI.create("jar:file:/path/to/main.jar!/META-INF/%76ersions/");
assertTrue(URIUtil.equalsIgnoreEncodings(uriA, uriB));
uriA = URI.create("JAR:FILE:/path/to/main.jar!/META-INF/versions/");
uriB = URI.create("jar:file:/path/to/main.jar!/META-INF/versions/");
assertTrue(URIUtil.equalsIgnoreEncodings(uriA, uriB));
}
@Test
public void testJarSource() throws Exception
{