Bug 61200 - URL Encoded Space getting encoded again during rewrite
Summary: URL Encoded Space getting encoded again during rewrite
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.44
Hardware: Other All
: P2 major (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-19 10:11 UTC by Santhana Preethi
Modified: 2017-06-20 04:44 UTC (History)
1 user (show)



Attachments
Encoded space test case (3.61 KB, text/x-csrc)
2017-06-19 10:11 UTC, Santhana Preethi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Santhana Preethi 2017-06-19 10:11:23 UTC
Created attachment 35061 [details]
Encoded space test case

After update to tomcat 8.0.44, there are some behaviour differences in URL Rewrite. 

URL encoded space (+) gets re-encoded as %2B after rewrite and param value gets modified to + instead of space.

From the changelog, seems like below change related to encoding seems to be the cause. 

"Review those places where Tomcat re-encodes a URI or URI component and ensure that that correct encoding (path differs from query string) is applied and that the encoding is applied consistently."

Attached test case which passes in 8.0.43 but fails in 8.0.44
Comment 1 Mark Thomas 2017-06-19 16:38:05 UTC
Thanks for the test case. It makes it much, much easier to work with a bug report that includes a test case.

This particular report is invalid.

The test set-up does this:
String url = "/a/" + URLEncoder.encode("Test Query", "UTF-8");

This results in a value for url of "/a/Test+query". And there lies the problem. It is only valid to encode a ' ' with '+' in a query string so in this test case the '+' gets treated as a literal '+' and is correctly encoded to %2B.

If the test is modified so url is correctly encoded:
String url = "/a/Test%20Query";

the test passes as expected.
Comment 2 Santhana Preethi 2017-06-20 04:44:35 UTC
(In reply to Mark Thomas from comment #1)
> Thanks for the test case. It makes it much, much easier to work with a bug
> report that includes a test case.
> 
> This particular report is invalid.
> 
> The test set-up does this:
> String url = "/a/" + URLEncoder.encode("Test Query", "UTF-8");
> 
> This results in a value for url of "/a/Test+query". And there lies the
> problem. It is only valid to encode a ' ' with '+' in a query string so in
> this test case the '+' gets treated as a literal '+' and is correctly
> encoded to %2B.
> 
> If the test is modified so url is correctly encoded:
> String url = "/a/Test%20Query";
> 
> the test passes as expected.

Thanks for the clarification.