diff --git a/src/uws/service/UWSUrl.java b/src/uws/service/UWSUrl.java index 5b0cea96..78215b9c 100644 --- a/src/uws/service/UWSUrl.java +++ b/src/uws/service/UWSUrl.java @@ -148,6 +148,11 @@ protected static final String normalizeURI(String uri){ uri = uri.trim(); if (uri.length() > 0 && uri.charAt(0) != '/') uri = "/" + uri; + + // Trim out duplicate leading slashes + while(uri.length() >= 2 && uri.charAt(1) == '/') + uri = uri.substring(1); + while(uri.length() >= 1 && uri.charAt(uri.length() - 1) == '/') uri = uri.substring(0, uri.length() - 1).trim(); return uri.trim(); diff --git a/src/uws/service/error/DefaultUWSErrorWriter.java b/src/uws/service/error/DefaultUWSErrorWriter.java index 8d7e7820..a58f700e 100644 --- a/src/uws/service/error/DefaultUWSErrorWriter.java +++ b/src/uws/service/error/DefaultUWSErrorWriter.java @@ -33,7 +33,6 @@ import org.json.JSONException; import org.json.JSONWriter; -import tap.TAPException; import uws.AcceptHeader; import uws.UWSException; import uws.UWSToolBox; diff --git a/test/uws/service/TestUWSUrl.java b/test/uws/service/TestUWSUrl.java index a83b883f..fabff1cb 100644 --- a/test/uws/service/TestUWSUrl.java +++ b/test/uws/service/TestUWSUrl.java @@ -557,4 +557,20 @@ public void testLoadHttpServletRequest(){ } } + @Test + public void testNormalizeURI() { + + assertEquals("Leading slash", "/async", UWSUrl.normalizeURI("/async")); + assertEquals("No leading slash", "/async1", UWSUrl.normalizeURI("async1")); + assertEquals("Double leading slash", "/async", UWSUrl.normalizeURI("//async ")); + assertEquals("Quad leading slash", "/async1", UWSUrl.normalizeURI("////async1")); + assertEquals("Leading and trailing space", "/async2", UWSUrl.normalizeURI(" /async2 ")); + + assertEquals("Leading and trailing slash", "/async", UWSUrl.normalizeURI("/async/")); + assertEquals("No leading slash, with trailing slash", "/async1", UWSUrl.normalizeURI("async1/")); + assertEquals("Double leading and trailing slash", "/async", UWSUrl.normalizeURI("//async//")); + assertEquals("Quad leading and trailing slash", "/async1", UWSUrl.normalizeURI("////async1////")); + assertEquals("Leading and trailing space with trailing slash", "/async2", UWSUrl.normalizeURI(" /async2/ ")); + } + }