Skip to content

Commit

Permalink
[#73] Avoid String creation using system default charset
Browse files Browse the repository at this point in the history
Used `StandardCharsets.UTF_8` to create `String` in `JSONParserByteArray` to avoid dependency on system's default charset
  • Loading branch information
dpeger committed Apr 23, 2021
1 parent 47a5b02 commit 340faf5
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import net.minidev.json.JSONValue;
import net.minidev.json.writer.JsonReaderI;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
*
Expand Down Expand Up @@ -59,7 +62,7 @@ public <T> T parse(byte[] in, JsonReaderI<T> mapper) throws ParseException {
}

protected void extractString(int beginIndex, int endIndex) {
xs = new String(in, beginIndex, endIndex - beginIndex);
xs = new String(in, beginIndex, endIndex - beginIndex, StandardCharsets.UTF_8);
}

protected void extractStringTrim(int start, int stop) {
Expand All @@ -71,7 +74,7 @@ protected void extractStringTrim(int start, int stop) {
while ((start < stop) && (val[stop - 1] <= ' ')) {
stop--;
}
xs = new String(in, start, stop - start);
xs = new String(in, start, stop - start, StandardCharsets.UTF_8);
}

protected int indexOf(char c, int pos) {
Expand Down

0 comments on commit 340faf5

Please sign in to comment.