Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#116 - Allow multiple trailing slash on base url #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/uws/service/UWSUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/uws/service/error/DefaultUWSErrorWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.json.JSONException;
import org.json.JSONWriter;

import tap.TAPException;
import uws.AcceptHeader;
import uws.UWSException;
import uws.UWSToolBox;
Expand Down
16 changes: 16 additions & 0 deletions test/uws/service/TestUWSUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/ "));
}

}