Don't URL decode/encode values if base64 decoding/encoding is enabled

This commit is contained in:
kuroppoi
2023-06-28 03:47:44 +02:00
parent 8759f17674
commit 26dbfd0edb
2 changed files with 10 additions and 10 deletions

View File

@@ -98,15 +98,14 @@ public class UrlEncodedFormGenerator extends SimpleGeneratorBase {
writer.write('=');
}
String value = text;
// Encode value as base64 if feature is enabled
// Otherwise, encode using URLEncoder.
if(Feature.BASE64_ENCODE_VALUES.enabledIn(formatFeatures)) {
value = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.ISO_8859_1))
.replace('=', '*').replace('+', '.').replace('/', '-');
writer.write(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.ISO_8859_1))
.replace('=', '*').replace('+', '.').replace('/', '-'));
} else {
writer.write(URLEncoder.encode(text, StandardCharsets.UTF_8));
}
writer.write(URLEncoder.encode(value, StandardCharsets.UTF_8));
}
@Override

View File

@@ -101,13 +101,14 @@ public class UrlEncodedFormParser extends SimpleParserBase {
_currToken = JsonToken.VALUE_STRING;
// Decode base64 if feature is enabled
// Otherwise, decode using URLDecoder.
if(Feature.BASE64_DECODE_VALUES.enabledIn(formatFeatures)) {
parsedString = new String(Base64.getDecoder().decode(
parsedString.replace('*', '=').replace('.', '+').replace('-', '/')), StandardCharsets.ISO_8859_1);
context.setCurrentValue(new String(Base64.getDecoder().decode(
parsedString.replace('*', '=').replace('.', '+').replace('-', '/')), StandardCharsets.ISO_8859_1));
} else {
context.setCurrentValue(URLDecoder.decode(parsedString, StandardCharsets.UTF_8));
}
context.setCurrentValue(URLDecoder.decode(parsedString, StandardCharsets.UTF_8));
if(i != '&') {
if(i != -1) {
_reportUnexpectedChar(i, "expected '&' to mark end of value and start of new key");