Updated Branches: refs/heads/wicket-1.5.x 06000ba0f -> e2a5dda1b
WICKET-4803 UrlDecoder should log a message when invalid input is provided Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e2a5dda1 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e2a5dda1 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e2a5dda1 Branch: refs/heads/wicket-1.5.x Commit: e2a5dda1bfca14226d807faa8d82e59ef45b20db Parents: 06000ba Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Authored: Wed Feb 20 10:11:28 2013 +0200 Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Committed: Wed Feb 20 10:12:03 2013 +0200 ---------------------------------------------------------------------- .../java/org/apache/wicket/request/UrlDecoder.java | 17 +++++++++--- .../org/apache/wicket/request/UrlDecoderTest.java | 20 +++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/e2a5dda1/wicket-request/src/main/java/org/apache/wicket/request/UrlDecoder.java ---------------------------------------------------------------------- diff --git a/wicket-request/src/main/java/org/apache/wicket/request/UrlDecoder.java b/wicket-request/src/main/java/org/apache/wicket/request/UrlDecoder.java index 0738d10..58ff656 100644 --- a/wicket-request/src/main/java/org/apache/wicket/request/UrlDecoder.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/UrlDecoder.java @@ -20,6 +20,8 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import org.apache.wicket.util.string.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Adapted from java.net.URLDecoder, but defines instances for query string decoding versus URL path @@ -34,6 +36,8 @@ import org.apache.wicket.util.string.Strings; */ public class UrlDecoder { + private static final Logger LOG = LoggerFactory.getLogger(UrlDecoder.class); + private final boolean decodePlus; /** @@ -144,8 +148,10 @@ public class UrlDecoder // "%x" will cause an exception to be thrown if ((i < numChars) && (c == '%')) { - throw new IllegalArgumentException( - "URLDecoder: Incomplete trailing escape (%) pattern"); + LOG.info("Incomplete trailing escape (%) pattern in '%s'. The escape character (%) will be ignored.", + s); + i++; + break; } try @@ -159,9 +165,10 @@ public class UrlDecoder } catch (NumberFormatException e) { - throw new IllegalArgumentException( - "URLDecoder: Illegal hex characters in escape (%) pattern - " + - e.getMessage()); + LOG.info("Illegal hex characters in escape (%) pattern in '{}'. " + + "The escape character (%) will be ignored. NumberFormatException: {} ", + s, e.getMessage()); + i++; } break; http://git-wip-us.apache.org/repos/asf/wicket/blob/e2a5dda1/wicket-request/src/test/java/org/apache/wicket/request/UrlDecoderTest.java ---------------------------------------------------------------------- diff --git a/wicket-request/src/test/java/org/apache/wicket/request/UrlDecoderTest.java b/wicket-request/src/test/java/org/apache/wicket/request/UrlDecoderTest.java index 90d913f..033ab03 100644 --- a/wicket-request/src/test/java/org/apache/wicket/request/UrlDecoderTest.java +++ b/wicket-request/src/test/java/org/apache/wicket/request/UrlDecoderTest.java @@ -39,4 +39,24 @@ public class UrlDecoderTest assertEquals(-1, decoded.indexOf('\0')); assertEquals("http://www.devil.com/highway?destination=NULLhell", decoded); } + + /** + * https://issues.apache.org/jira/browse/WICKET-4803 + * @throws Exception + */ + @Test + public void badUrlEntities() throws Exception + { + String url = "http://localhost/test?a=%%%"; + String decoded = UrlDecoder.QUERY_INSTANCE.decode(url, "UTF-8"); + assertEquals("http://localhost/test?a=", decoded); + + url = "http://localhost/test?%%%"; + decoded = UrlDecoder.QUERY_INSTANCE.decode(url, "UTF-8"); + assertEquals("http://localhost/test?", decoded); + + url = "http://localhost/test?%a=%b%"; + decoded = UrlDecoder.QUERY_INSTANCE.decode(url, "UTF-8"); + assertEquals("http://localhost/test?a=b", decoded); + } }