From c5d4897a5f352a0f5112710b9c6f1fcf39ff645b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 28 Mar 2018 10:48:28 -0500 Subject: [PATCH] Issue #2387 - fixing URIUtil.equalsIgnoreEncoding() with jar:file:// uris Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/util/URIUtil.java | 12 ++++++-- .../org/eclipse/jetty/util/URIUtilTest.java | 28 +++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java index 0bc897e0056..01bf07875e5 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java @@ -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()); } /** diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java index d270791f476..bd5e831c279 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java @@ -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 {