Skip to content

Commit ba6babd

Browse files
committed
fix checking a surrogate pair
1 parent e48a7a1 commit ba6babd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: src/main/java/com/jsoniter/output/StreamImplString.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ private static void writeStringSlowPathWithoutEscapeUnicode(JsonStream stream, S
175175
int firstPart = _surrogate;
176176
_surrogate = 0;
177177
// Ok, then, is the second part valid?
178-
if (c < SURR2_FIRST || c > SURR2_LAST) {
179-
throw new JsonException("Broken surrogate pair: first char 0x" + Integer.toHexString(firstPart) + ", second 0x" + Integer.toHexString(c) + "; illegal combination");
178+
int secondPart = val.charAt(++i);
179+
if (secondPart < SURR2_FIRST || secondPart > SURR2_LAST) {
180+
throw new JsonException("Broken surrogate pair: first char 0x" + Integer.toHexString(firstPart) + ", second 0x" + Integer.toHexString(secondPart) + "; illegal combination");
180181
}
181-
c = 0x10000 + ((firstPart - SURR1_FIRST) << 10) + (c - SURR2_FIRST);
182+
c = 0x10000 + ((firstPart - SURR1_FIRST) << 10) + (secondPart - SURR2_FIRST);
182183
if (c > 0x10FFFF) { // illegal in JSON as well as in XML
183184
throw new JsonException("illegalSurrogate");
184185
}

0 commit comments

Comments
 (0)