crawling of filenames with + fails due to url decoding

modified UTF8.decodeURL to apply x-www-form-urlencoded ( space -> + ) to the query part of the url only.
pull/1/head
reger 11 years ago
parent 3b559e7846
commit 982601017e

@ -211,21 +211,32 @@ public class UTF8 implements Comparator<String> {
/** /**
* Decodes a <code>application/x-www-form-urlencoded</code> string using a specific * Decodes a <code>application/x-www-form-urlencoded</code> string using a specific
* encoding scheme. * encoding scheme.
* for url query part only application/x-www-form-urlencoded (+ -> space) is applied
*/ */
public static String decodeURL(final String s) { public static String decodeURL(final String s) {
boolean needToChange = false; boolean needToChange = false;
final int numChars = s.length(); final int numChars = s.length();
final StringBuilder sb = new StringBuilder(numChars > 500 ? numChars / 2 : numChars); final StringBuilder sb = new StringBuilder(numChars > 500 ? numChars / 2 : numChars);
int i = 0; int i = 0;
boolean insearchpart = false;
char c; char c;
byte[] bytes = null; byte[] bytes = null;
while (i < numChars) { while (i < numChars) {
c = s.charAt(i); c = s.charAt(i);
switch (c) { switch (c) {
case '+': case '?' : // mark start of query part (to start x-www-form-urlencoded)
sb.append(' '); sb.append(c);
i++; i++;
insearchpart = true; // flag to start x-www-form + decoding
break;
case '+': //application/x-www-form-urlencoded (in searchpart)
if (insearchpart) {
sb.append(' ');
needToChange = true; needToChange = true;
} else {
sb.append(c);
}
i++;
break; break;
case '%': case '%':
try { try {

Loading…
Cancel
Save