Closed
Description
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:
- Spring request mapping annotation does not map an encoded URI correctly [SPR-10306] #14940 Spring request mapping annotation does not map an encoded URI correctly ("duplicates")