-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
2.2.28.Final
There is a bit of a catch-22 that makes it basically impossible to use the rewrite() handler with any URL containing encoded characters, such as a space.
Take for example, the following URL:
localhost/foo%20bar
and the following simple rewrite:
rewrite( '/index.cfm%{REQUEST_URL}' )
The final URL will incorrectly be this:
localhost/index.cfm/foo%2520bar
which double encodes the space.
The issue is two fold:
- The rewrite() handler uses the RelativePathAttribute which specifically requires a decoded path as it will encode any % chars it contains
- The only exchange attributes for getting the request URL ( %{REQUEST_PATH}, and
%{RELATIVE_PATH} ) both represent the encoded form of the URI. The exchange has the decoded version of the URI as exchange.getRequestPath() but there is no exchange attribute in the predicate language to access it!
I'll also point out it's quite confusing that the predicate attribute actually called REQUEST_PATH doesn't actually return the exchanges request path, but instead the relative path!
So basically, how do you do a rewrite of the path and not get double-encoded characters? I'll also point out, this ticket of mine from 2 years ago would have offered a workaround had it been completed :/
https://issues.redhat.com/browse/UNDERTOW-2120
I recommend adding a new exchange attribute to the predicate language called %{DECODED_REQUEST_PATH} which returns the actual exchange.getRequestPath() as I have done in my app here:
I also recommend improving the docs for the rewrite handler to make it more clear it requires a decoded path.
https://undertow.io/undertow-docs/undertow-docs-2.0.0/#rewrite-handler