You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/02/20 09:15:25 UTC

[1/2] git commit: WICKET-4803 UrlDecoder should log a message when invalid input is provided

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/95438497
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/95438497
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/95438497

Branch: refs/heads/master
Commit: 954384975e618ea3ee9954a8546fb94a01e24c88
Parents: 73300e7
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 20 10:11:28 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Feb 20 10:11:53 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/util/encoding/UrlDecoder.java    |   17 +++++++++---
 .../wicket/util/encoding/UrlDecoderTest.java       |   20 +++++++++++++++
 2 files changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/95438497/wicket-util/src/main/java/org/apache/wicket/util/encoding/UrlDecoder.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/encoding/UrlDecoder.java b/wicket-util/src/main/java/org/apache/wicket/util/encoding/UrlDecoder.java
index a950fde..2e2f969 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/encoding/UrlDecoder.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/encoding/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/95438497/wicket-util/src/test/java/org/apache/wicket/util/encoding/UrlDecoderTest.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/encoding/UrlDecoderTest.java b/wicket-util/src/test/java/org/apache/wicket/util/encoding/UrlDecoderTest.java
index 6564fd6..334ecfc 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/encoding/UrlDecoderTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/encoding/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);
+	}
 }