Bug 60116

Summary: NC matches in the Rewrite Valve cause matched groups to be lower case.
Product: Tomcat 8 Reporter: Sebastiaan van Erk <sebster>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.5.x-trunk   
Target Milestone: ----   
Hardware: All   
OS: All   

Description Sebastiaan van Erk 2016-09-12 07:08:46 UTC
I have the following rewrite rule:

RewriteCond %{REQUEST_URI} /test
RewriteCond %{QUERY_STRING} .*a=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).* [NC]
RewriteRule .* - [E=X-Tenant-Id:%1,L]

This matches the query string to the supplied pattern in a case insensitive way. However, the back reference %1 is always lower case, independent of the actual query string. That is, if the query string is:

    http://localhost:8080/test?a=CFA2AFDF-5D36-4D1F-B798-430557CF4355

the matched back reference %1 is cfa2afdf-5d36-4d1f-b798-430557cf4355.

This is strange and unexpected. It is also not how NC works in The Apache HTTP server mod_rewrite, which just does the test in a case insensitive way but returns the actual matched group. Case insensitive Java regular expressions also do not change the case of any of the matched groups.
Comment 1 Mark Thomas 2016-09-12 22:19:44 UTC
This has been fixed in the following branches:
- 9.0.x for 9.0.0.M11 onwards
- 8.5.x for 8.5.6 onwards
- 8.0.x for 8.0.38 onwards