Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,10 @@ public String readString() {

char c = chars[offset];
if (c == '\\') {
c = chars[++offset];
if (++offset == end) {
throw error("invalid escape character EOI");
}
Comment thread
annoymous3 marked this conversation as resolved.
Resolved
c = chars[offset];
if (c == 'u') {
c = (char) hexDigit4(chars, offset + 1, end);
offset += 4;
Expand Down
25 changes: 25 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/JSONReaderUTF16Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.alibaba.fastjson2;

import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class JSONReaderUTF16Test {
@Test
public void truncatedEscape() {
String[] inputs = {
"\"\\",
"{\"a\":\"\\",
"[\"\\",
"\"ab\\"
};

for (String input : inputs) {
assertThrows(JSONException.class, () -> JSON.parse(input));
Comment thread
annoymous3 marked this conversation as resolved.
Resolved
assertThrows(JSONException.class, () -> JSON.parse(input.toCharArray()));
assertThrows(JSONException.class, () -> JSON.parse(input.getBytes(StandardCharsets.UTF_8)));
Comment thread
annoymous3 marked this conversation as resolved.
Resolved
}
}
}
Loading