Permalink
Browse files

Fix unescape of URLs having some '%' chars but not percent-encoded

  • Loading branch information...
luccioman committed May 30, 2017
1 parent bd88fd3 commit c226ded799ff2b9a181d38ac0d88ac88365c35b1
@@ -688,7 +688,7 @@ public static StringBuilder escape(final String s) {
* Decodes a <code>application/x-www-form-urlencoded</code> string using UTF-8 encoding.
*
* @param s the string to decode
* @return the newly decoded string
* @return the newly decoded string, or the original string when it doesn't match the <code>application/x-www-form-urlencoded</code> format
*/
public static String unescape(final String s) {
try {
@@ -697,6 +697,15 @@ public static String unescape(final String s) {
/* This should not happen */
ConcurrentLog.logException(e);
return s;
} catch(Exception e) {
/*
* URLDecode may throw an IllegalArgumentException (or any other
* Exception in future implementations) when the string doesn't
* match the application/x-www-form-urlencoded format: in that case
* return the original string.
* Example case : when the valid '%' character is used in a URL but without percent encoding purpose.
*/
return s;
}
}
@@ -368,6 +368,7 @@ public void testUnescape() {
new String[] { "unencoded rfc3986 unreserved ascii chars:-.~_",
"unencoded rfc3986 unreserved ascii chars:-.~_" },
new String[] { "http://simpleurl.com/", "http://simpleurl.com/" },
new String[] { "http://not-a-x-www-form-urlencoded.com/example.php?params=a|b&paramwithpercent=%param%", "http://not-a-x-www-form-urlencoded.com/example.php?params=a|b&paramwithpercent=%param%" },
new String[] {
"http://url-with-unencoded-query-and-anchor.net/path?q=asciiquery&p1=param1&p2=pâräm2&p3=简化字#anchor",
"http://url-with-unencoded-query-and-anchor.net/path?q=asciiquery&p1=param1&p2=pâräm2&p3=简化字#anchor" }, };

0 comments on commit c226ded

Please sign in to comment.