From 232b4a46803ae2efbceafb01699e51d70390ecb8 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 22 Jul 2015 13:01:21 +1000 Subject: [PATCH] 473006 - Encode addPath in URLResource --- .../jetty/util/resource/URLResource.java | 2 +- .../jetty/util/resource/ResourceTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java index 2d5fd872ee0..793b4e0f3e4 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java @@ -301,7 +301,7 @@ public class URLResource extends Resource path = URIUtil.canonicalPath(path); - return newResource(URIUtil.addPaths(_url.toExternalForm(),path), _useCaches); + return newResource(URIUtil.addPaths(_url.toExternalForm(),URIUtil.encodePath(path)), _useCaches); } /* ------------------------------------------------------------ */ diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java index 8d3ca20ebf2..121e314b713 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java @@ -38,6 +38,8 @@ import java.util.zip.ZipFile; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.OS; import org.eclipse.jetty.util.IO; +import org.hamcrest.Matchers; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -343,6 +345,21 @@ public class ResourceTest assertEquals(last,r.lastModified()); } } + + /* ------------------------------------------------------------ */ + @Test + public void testEncodeAddPath () + throws Exception + { + Resource r; + + r = Resource.newResource(__userURL+"TestData/").addPath("foo%/b r"); + Assert.assertThat(r.getURI().toString(),Matchers.endsWith("/foo%25/b%20r")); + + r = Resource.newResource("jar:"+__userURL+"TestData/test.zip!/subdir/").addPath("foo%/b r"); + Assert.assertThat(r.getURI().toString(),Matchers.endsWith("/foo%25/b%20r")); + } + /* ------------------------------------------------------------ */ @Test