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

Spring URI template class does not encode a URI correctly [SPR-10305] #14939

Closed
spring-projects-issues opened this issue Feb 15, 2013 · 0 comments
Assignees
Labels
in: web status: duplicate

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 15, 2013

Alexander Hawley opened SPR-10305 and commented

When using the Spring template class (org.springframework.web.util.UriTemplate), the expand method does not encode a URI correctly. Some reserved characters are not encoded ever, others only sometimes.

For example, the slash character / should be encoded as %2f.

I've tried every permutation I could think of. Templating, not templating, parameters, et al.

Results as follows.

List of strings which contain reserved characters:

List<String> paths = Arrays.asList(
    "foo%boo"
    ,"foo/boo"
    ,"foo?boo"
    ,"foo=boo"
    ,"foo&boo"
    ,"foo#boo"
    ,"foo$boo"
    ,"foo+boo"
    ,"foo,boo"
    ,"foo:boo"
    ,"foo;boo"
    ,"foo@boo"
);

Java to utilize the URI template class:

for (String path : paths) {
    System.out.println("path: \"" + path + "\"");
    System.out.println("UriTemplate#expand: \"" + (new UriTemplate("{path}")).expand(path).toString() + "\"");
    System.out.println("UriTemplate#expand, path: \"" + (new UriTemplate("http://domain.com/{path}")).expand(path).toString() + "\"");
    System.out.println("UriTemplate#expand, query: \"" + (new UriTemplate("http://domain.com/?{path}")).expand(path).toString() + "\"");
    System.out.println("UriTemplate#expand, query param: \"" + (new UriTemplate("http://domain.com/?param={path}")).expand(path).toString() + "\"");
}

Result:

path: "foo%boo"
UriTemplate#expand: "foo%25boo"
UriTemplate#expand, path: "http://domain.com/foo%25boo"
UriTemplate#expand, query: "http://domain.com/?foo%25boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo%25boo"

path: "foo/boo"
UriTemplate#expand: "foo/boo"
UriTemplate#expand, path: "http://domain.com/foo/boo"
UriTemplate#expand, query: "http://domain.com/?foo/boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo/boo"

path: "foo?boo"
UriTemplate#expand: "foo%3Fboo"
UriTemplate#expand, path: "http://domain.com/foo%3Fboo"
UriTemplate#expand, query: "http://domain.com/?foo?boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo?boo"

path: "foo=boo"
UriTemplate#expand: "foo=boo"
UriTemplate#expand, path: "http://domain.com/foo=boo"
UriTemplate#expand, query: "http://domain.com/?foo%3Dboo"
UriTemplate#expand, query param: "http://domain.com/?param=foo%3Dboo"

path: "foo&boo"
UriTemplate#expand: "foo&boo"
UriTemplate#expand, path: "http://domain.com/foo&boo"
UriTemplate#expand, query: "http://domain.com/?foo%26boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo%26boo"

path: "foo#boo"
UriTemplate#expand: "foo%23boo"
UriTemplate#expand, path: "http://domain.com/foo%23boo"
UriTemplate#expand, query: "http://domain.com/?foo%23boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo%23boo"

path: "foo$boo"
UriTemplate#expand: "foo$boo"
UriTemplate#expand, path: "http://domain.com/foo$boo"
UriTemplate#expand, query: "http://domain.com/?foo$boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo$boo"

path: "foo+boo"
UriTemplate#expand: "foo+boo"
UriTemplate#expand, path: "http://domain.com/foo+boo"
UriTemplate#expand, query: "http://domain.com/?foo%2Bboo"
UriTemplate#expand, query param: "http://domain.com/?param=foo%2Bboo"

path: "foo,boo"
UriTemplate#expand: "foo,boo"
UriTemplate#expand, path: "http://domain.com/foo,boo"
UriTemplate#expand, query: "http://domain.com/?foo,boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo,boo"

path: "foo:boo"
UriTemplate#expand: "foo:boo"
UriTemplate#expand, path: "http://domain.com/foo:boo"
UriTemplate#expand, query: "http://domain.com/?foo:boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo:boo"

path: "foo;boo"
UriTemplate#expand: "foo;boo"
UriTemplate#expand, path: "http://domain.com/foo;boo"
UriTemplate#expand, query: "http://domain.com/?foo;boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo;boo"

path: "foo@boo"
UriTemplate#expand: "foo@boo"
UriTemplate#expand, path: "http://domain.com/foo@boo"
UriTemplate#expand, query: "http://domain.com/?foo@boo"
UriTemplate#expand, query param: "http://domain.com/?param=foo@boo"

Any ideas?

Thanks.

-AH


Affects: 3.1 GA

Issue Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: duplicate
Projects
None yet
Development

No branches or pull requests

2 participants