Skip to content

fix checking a surrogate pair #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix checking a surrogate pair
  • Loading branch information
t-mangoe committed Apr 7, 2019
commit ba6babd829c267e763ede206acd2950c3c0cc5d0
7 changes: 4 additions & 3 deletions src/main/java/com/jsoniter/output/StreamImplString.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ private static void writeStringSlowPathWithoutEscapeUnicode(JsonStream stream, S
int firstPart = _surrogate;
_surrogate = 0;
// Ok, then, is the second part valid?
if (c < SURR2_FIRST || c > SURR2_LAST) {
throw new JsonException("Broken surrogate pair: first char 0x" + Integer.toHexString(firstPart) + ", second 0x" + Integer.toHexString(c) + "; illegal combination");
int secondPart = val.charAt(++i);
if (secondPart < SURR2_FIRST || secondPart > SURR2_LAST) {
throw new JsonException("Broken surrogate pair: first char 0x" + Integer.toHexString(firstPart) + ", second 0x" + Integer.toHexString(secondPart) + "; illegal combination");
}
c = 0x10000 + ((firstPart - SURR1_FIRST) << 10) + (c - SURR2_FIRST);
c = 0x10000 + ((firstPart - SURR1_FIRST) << 10) + (secondPart - SURR2_FIRST);
if (c > 0x10FFFF) { // illegal in JSON as well as in XML
throw new JsonException("illegalSurrogate");
}
Expand Down