-
Notifications
You must be signed in to change notification settings - Fork 475
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
Special characters in path variables are escaped multiple times when added with slash() #40
Comments
I too think I am seeing this behaviour, when trying to include a "{" in a path segment via a path parameter in the MVC Controller method mapping. The resulting encoding is "%257B" instead of the expected "%7B", due to double encoding. I did a little picking through the source, and basically is seems the parameter is encoded once when going through the "expand" process for the URL template generated from controller method, then the entire path value is re-encoded when adding the link to the resource. Rough description... |
I have a simmilar issue when using
imho it should be:
|
If someone faces the same issue, here is my workaround:
|
Seems related to #96 which is marked as fixed, but it doesn't seem to be, I'm having the same issue using the LinkBuilder in various ways:
Same happens using the
|
It appears that the problem is in UriTemplate:
This expandedComponents.encode() is causing any arguments for the URI template to be encoded. When the URI is encoded once again later .... |
We've just pushed a removals for an unnecessary back-and-forth conversion in the course of the fix for #398. Does that maybe even fix that issue here? |
This fixes my first test (thanks!), so the following passes: Link l = linkToCurrentMapping().slash("first")
.slash("sec%ond").slash("thi%rd").slash("fourth").withSelfRel();
assertEquals("http://localhost/first/sec%25ond/thi%25rd/fourth", l.getHref()); However, it doesn't encode any linkToCurrentMapping().slash("first")
.slash("sec/ond").slash("third").withSelfRel(); I would like |
To support this, we'd need to pre-encode the |
I think it's safe to say that if you NEED to encode a "/" and NOT have it split into two paths, you are responsible for that. There is little way in framework code to detect this rare corner case. |
I'm trying to use a URI-encoded value as a path segment value when constructing a link with LinkBuilder's slash() method, but I find that any 'special' characters (such as %) will be repeatedly double-encoded by each subsequent slash() call.
For example:
Should return
http://localhost/first/sec%25ond/thi%25rd/fourth
but getshttp://localhost/first/sec%252525ond/thi%2525rd/fourth
I think that this is being caused by LinkBuilderSupport's interaction with HierarchicalUriComponentBuilder.toUri and URI (which always encodes the path).
Note that I'm actually trying to percent-encode a path as a path segment value, but if I don't explicitly percent-encode slashes in the path, then they are not encoded at all:
I would like
http://localhost/first/sec%2Fond/third/fourth
but gethttp://localhost/first/sec/ond/third
(due to theStringUtils.tokenizeToStringArray(object.toString(), "/")
call in LinkBuilderSupport.slash).Here's the full unit test: https://gist.github.com/4436408
The text was updated successfully, but these errors were encountered: