Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Fix unescape of URLs having some '%' chars but not percent-encoded
lucciomanc226ded799ff
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.javaindex 7a42826a2..2b155b6ce 100644--- a/source/net/yacy/cora/document/id/MultiProtocolURL.java+++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java@@ -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;}}diff --git a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.javaindex a2ba443f5..482ccc2c7 100644--- a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java+++ b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java@@ -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¶mwithpercent=%param%", "http://not-a-x-www-form-urlencoded.com/example.php?params=a|b¶mwithpercent=%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" }, };