Skip to content

Commit e2d2d76

Browse files
committed
#93 fix control character serialization
1 parent ee0a9e1 commit e2d2d76

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/main/java/com/jsoniter/output/StreamImplString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static void writeStringSlowPath(JsonStream stream, String val, int i, in
132132
if (escapeUnicode) {
133133
for (; i < valLen; i++) {
134134
int c = val.charAt(i);
135-
if (c > 125) {
135+
if (c > 125 || c < 32) {
136136
byte b4 = (byte) (c & 0xf);
137137
byte b3 = (byte) (c >> 4 & 0xf);
138138
byte b2 = (byte) (c >> 8 & 0xf);

src/test/java/com/jsoniter/output/TestString.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ public void test_unicode() {
88
String output = JsonStream.serialize(new Config.Builder().escapeUnicode(false).build(), "中文");
99
assertEquals("\"中文\"", output);
1010
}
11+
public void test_escape_control_character() {
12+
String output = JsonStream.serialize(new String(new byte[]{0}));
13+
assertEquals("\"\\u0000\"", output);
14+
}
1115
}

0 commit comments

Comments
 (0)