Skip to content

Commit

Permalink
Don't modify the static character replacement table (#5)
Browse files Browse the repository at this point in the history
When `#string()` gets called with `escapeQuotes == false`, it would
remove the replacement for `"` from the table without restoring it.
This, in turn, will cause later calls not to escape the quotes, even if
`escapeQuotes == true`.

Modifying the table is ugly IMO, I think it's better to do special check
for quote character.
  • Loading branch information
deirn authored Dec 7, 2024
1 parent 00803c4 commit 21caef5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions json/src/main/java/org/quiltmc/parsers/json/JsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,16 @@ private void string(String value, boolean quotes, boolean escapeQuotes) throws I
out.write('\"');
}

if (!escapeQuotes) {
replacements['\"'] = null;
}

int last = 0;
int length = value.length();

for (int i = 0; i < length; i++) {
char c = value.charAt(i);
String replacement;
if (c < 128) {
if (c == '"' && !escapeQuotes) {
continue;
}
replacement = replacements[c];
if (replacement == null) {
continue;
Expand Down

0 comments on commit 21caef5

Please sign in to comment.