Bug 50721 - RequestUtil.URLDecode() throws IllegalArgumentException for URLs with %xx-Code as last character
Summary: RequestUtil.URLDecode() throws IllegalArgumentException for URLs with %xx-Cod...
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2011-02-04 20:42 UTC by Christof Marti
Modified: 2011-02-09 18:42 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Christof Marti 2011-02-04 20:42:49 UTC
When calling org.apache.catalina.util.RequestUtil.URLDecode() for a valid URL ending with a %xx-Code, the method throws the IllegalArgumentException "The % character must be followed by two hexademical digits".
This only happens, if the %xx-Code is at the  at the end of the URL. It works fine for URLs ending with normal characters.
RequestUtil.URLDecode("http://localhost:8080/webdav/test%C3%A4", "UTF8") fails
RequestUtil.URLDecode("http://localhost:8080/webdav/test%C3%A4n", "UTF8") works fine

The problem is with the the test in line 329 (added in revision: 905073):
if (ix + 2 >= len) {

Because the index ix is already incremented in line 325, after reading the current byte b (e.g. the %-character), this test fails if "%A4" is at the end, but does not fail for "%A4n".

Simple fix: In line 329 the '>=' should be replaced by a '>':
if (ix + 2 > len) {

This change should have no side effects, because ix is checked again before the next iteration.
Because this change is trivial I did not include a patch.

Best regards
Comment 1 Mark Thomas 2011-02-09 18:42:43 UTC
Thanks for the report. This has been fixed in 7.0.x and will be in 7.0.9 onwards.