fix issue with json unicode whitespace enscaping

This commit is contained in:
Grahame Grieve 2024-08-16 11:59:09 +08:00
parent 6e27c45d54
commit 3ee9533121
2 changed files with 6 additions and 2 deletions

View File

@ -1032,6 +1032,10 @@ public class Utilities {
public static String escapeJson(String value) {
return escapeJson(value, true);
}
public static String escapeJson(String value, boolean escapeUnicodeWhitespace) {
if (value == null)
return "";
@ -1049,7 +1053,7 @@ public class Utilities {
b.append("\\\\");
else if (c == ' ')
b.append(" ");
else if (c == '\r' || c == '\n') { // was isWhitespace(c), but this escapes unicode characters, and seems unnecessary
else if ((c == '\r' || c == '\n') || (isWhitespace(c) && escapeUnicodeWhitespace)) {
b.append("\\u"+Utilities.padLeft(Integer.toHexString(c), '0', 4));
} else if (((int) c) < 32)
b.append("\\u" + Utilities.padLeft(Integer.toHexString(c), '0', 4));

View File

@ -682,7 +682,7 @@ public class JsonParser {
break;
case STRING:
b.append("\"");
b.append(Utilities.escapeJson(((JsonString) e).getValue()));
b.append(Utilities.escapeJson(((JsonString) e).getValue(), false));
b.append("\"");
break;
default: