fix for path with char code > 255

(causing index out of bound exception)
+ test cas for it
pull/1/head
reger 10 years ago
parent 1d81bd0687
commit 7120ea42f1

@ -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 {

@ -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) {

Loading…
Cancel
Save