Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fix url (path) %-decoding http://mantis.tokeek.de/view.php?id=519 - add test case for this

regerf94e34058c45
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.java
index bb0e69cb1..fdc7847ef 100644
--- a/source/net/yacy/cora/document/id/MultiProtocolURL.java
+++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java
@@ -124,6 +124,15 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
this.port = url.port;
}
+ /**
+ * Create MultiProtocolURL
+ *
+ * decoding exception: if url string contains http url with char '%' the url string must be url encoded (percent-escaped) before
+ * as internal encoding is skipped if url string contains '%'.
+ *
+ * @param url '%' char url encoded before
+ * @throws MalformedURLException
+ */
public MultiProtocolURL(String url) throws MalformedURLException {
if (url == null) throw new MalformedURLException("url string is null");
@@ -133,8 +142,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
// identify protocol
assert (url != null);
url = url.trim();
- url = UTF8.decodeURL(url); // normalization here
- //url = patternSpace.matcher(url).replaceAll(" ");
+
if (url.startsWith("//")) {
// patch for urls starting with "//" which can be found in the wild
url = "http:" + url;
@@ -195,6 +203,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
identSearchpart();
escape();
} else {
+ url = UTF8.decodeURL(url); // normalization here
// this is not a http or ftp url
if (this.protocol.equals("mailto")) {
// parse email url
diff --git a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
index 394fc1a25..e3c7f5a2d 100644
--- a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
+++ b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
@@ -141,6 +141,30 @@ public class MultiProtocolURLTest {
}
}
+
+ /**
+ * Test of toNormalform method, of class MultiProtocolURL.
+ */
+ @Test
+ public void testToNormalform() throws Exception {
+ // some test url/uri with problems in the past
+ String[][] testStrings = new String[][]{
+ // teststring , expectedresult
+ new String[]{"http://www.heise.de/newsticker/thema/%23saukontrovers", "http://www.heise.de/newsticker/thema/%23saukontrovers"}, // http://mantis.tokeek.de/view.php?id=519
+ new String[]{"http://www.heise.de/newsticker/thema/#saukontrovers", "http://www.heise.de/newsticker/thema/"}
+ };
+
+ for (String[] testString : testStrings) {
+ // desired conversion result
+ System.out.print("orig uri: " + testString[0]);
+ String shouldBe = testString[1];
+ // conversion result
+ String resolvedHost = new MultiProtocolURL(testString[0]).toNormalform(true);
+ // test if equal
+ assertEquals(shouldBe, resolvedHost);
+ System.out.println(" -> " + resolvedHost);
+ }
+ }
}