fix throw Exception, for issue #3610
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (11, macos-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (11, ubuntu-24.04) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (11, windows-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (17, macos-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (17, ubuntu-24.04) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (17, windows-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (21, macos-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (21, ubuntu-24.04) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (21, windows-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (8, macos-latest) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (8, ubuntu-24.04) (push) Waiting to run Details
Java CI / Test on JDK ${{ matrix.java }} OS ${{ matrix.os }} (8, windows-latest) (push) Waiting to run Details

This commit is contained in:
wenshao 2025-07-27 12:56:51 +08:00
parent f17c3b56e6
commit 337aaaaba3
3 changed files with 37 additions and 2 deletions

View File

@ -1059,7 +1059,11 @@ final class JSONReaderASCII
this.nameLength = i;
this.nameEnd = offset;
offset++;
c = bytes[offset];
if (offset < end) {
c = bytes[offset];
} else {
c = EOI;
}
while (c <= ' ' && ((1L << c) & SPACE) != 0) {
offset++;

View File

@ -3106,7 +3106,11 @@ class JSONReaderUTF8
this.nameLength = i;
this.nameEnd = offset;
offset++;
ch = bytes[offset] & 0xff;
if (offset < end) {
ch = bytes[offset] & 0xff;
} else {
ch = EOI;
}
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
offset++;

View File

@ -0,0 +1,27 @@
package com.alibaba.fastjson2.issues_3600;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Issue3610 {
@Test
public void test() {
String str = "{\"screenWidth\":1920,\"isSupportSmallWindow\"";
assertThrows(JSONException.class, () -> JSON.parseObject(str.getBytes(StandardCharsets.UTF_8)));
assertThrows(JSONException.class, () -> JSON.parseObject(str.toCharArray()));
assertThrows(JSONException.class, () -> JSON.parseObject(str));
}
@Test
public void testUTF8() {
String str = "{\"中文\":1920,\"isSupportSmallWindow\"";
assertThrows(JSONException.class, () -> JSON.parseObject(str.getBytes(StandardCharsets.UTF_8)));
assertThrows(JSONException.class, () -> JSON.parseObject(str.toCharArray()));
assertThrows(JSONException.class, () -> JSON.parseObject(str));
}
}