SPR-6291 - UrlPathHelper is too aggressive decoding URLs

This commit is contained in:
Arjen Poutsma
2010-10-12 12:09:43 +00:00
parent 043ec2c8b2
commit c5c1d70aa3
2 changed files with 5 additions and 1 deletions

View File

@@ -462,6 +462,7 @@ public abstract class UriUtils {
Assert.hasLength(encoding, "'encoding' must not be empty");
int length = source.length();
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
boolean changed = false;
for (int i = 0; i < length; i++) {
int ch = source.charAt(i);
if (ch == '%') {
@@ -472,6 +473,7 @@ public abstract class UriUtils {
int l = Character.digit(hex2, 16);
bos.write((char) ((u << 4) + l));
i += 2;
changed = true;
}
else {
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
@@ -481,7 +483,7 @@ public abstract class UriUtils {
bos.write(ch);
}
}
return new String(bos.toByteArray(), encoding);
return changed ? new String(bos.toByteArray(), encoding) : source;
}
}