Skip to content

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

fix for path with char code > 255 (causing index out of bound exception) + test cas for it

reger7120ea42f1cd
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.java
index 0875aa66f..6442eddd7 100644
--- a/source/net/yacy/cora/document/id/MultiProtocolURL.java
+++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java
@@ -487,9 +487,10 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
*/
private void escapePath() {
final StringBuilder ptmp = new StringBuilder(this.path.length() + 10);
- final byte[] bpath = UTF8.getBytes(this.path);
boolean modified = false;
- for (byte b : bpath) {
+ final int len = this.path.length();
+ for (int i = 0; i < len; i++) {
+ int b = this.path.charAt(i) & 0xFF; // protect index out of bound exception (TODO: do we need to handle hichars > 255 or 2-byte chars here ?)
if (UNRESERVED_PATH.get(b)) {
ptmp.append((char) b);
} else {
diff --git a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
index c29b9700b..e4ccb9abd 100644
--- a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
+++ b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java
@@ -152,7 +152,9 @@ public class MultiProtocolURLTest {
// 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/"},
- new String[]{"http://www.liferay.com/community/wiki/-/wiki/Main/Wiki+Portlet", "http://www.liferay.com/community/wiki/-/wiki/Main/Wiki+Portlet"} // http://mantis.tokeek.de/view.php?id=559
+ new String[]{"http://www.liferay.com/community/wiki/-/wiki/Main/Wiki+Portlet", "http://www.liferay.com/community/wiki/-/wiki/Main/Wiki+Portlet"}, // http://mantis.tokeek.de/view.php?id=559
+ new String[]{"http://de.wikipedia.org/wiki/Philippe_Ariès", "http://de.wikipedia.org/wiki/Philippe_Ari%E8s"} // utf-8 2 byte char
+ // new String[]{"http://de.wikipedia.org/wiki/Philippe_Ariès", "http://de.wikipedia.org/wiki/Philippe_Ari%C3%A8s"} // above formal correct for utf8 codepage
};
for (String[] testString : testStrings) {