473006 - Encode addPath in URLResource

This commit is contained in:
Greg Wilkins 2015-07-22 13:01:21 +10:00
parent d8c94ea27b
commit 232b4a4680
2 changed files with 18 additions and 1 deletions

View File

@ -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);
}
/* ------------------------------------------------------------ */

View File

@ -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