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

pull/122/head
luccioman 8 years ago
parent bd88fd303e
commit c226ded799

@ -688,7 +688,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
* 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 class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
/* 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 class MultiProtocolURLTest {
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" }, };

Loading…
Cancel
Save