Skip to content
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

Fixed parsing exception for issue#1724 #1725

Merged
merged 2 commits into from
Aug 9, 2023
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
Next Next commit
fix: parsing exception for issue#1724
Signed-off-by: Kraity <kraty@krait.cn>
  • Loading branch information
kraity committed Aug 8, 2023
commit b8742b0444c280aa1bcb08070d1932f634c4a2ab
94 changes: 50 additions & 44 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderASCII.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,74 +48,85 @@ public final void next() {
}

public final boolean nextIfObjectStart() {
final byte[] bytes = this.bytes;
int offset = this.offset;
int ch = this.ch;
if (ch != '{') {
return false;
}
comma = false;

int offset = this.offset;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
return true;
}

ch = bytes[offset];
byte[] bytes = this.bytes;

ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
offset++;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset];
ch = bytes[offset++];
}

this.offset = offset + 1;
this.ch = (char) (ch & 0xFF);
this.offset = offset;

while (this.ch == '/' && this.offset < bytes.length && bytes[this.offset] == '/') {
skipLineComment();
}

return true;
}

public final boolean nextIfObjectEnd() {
final byte[] bytes = this.bytes;
int offset = this.offset;
int ch = this.ch;
if (ch == ']' || ch == EOI) {
throw new JSONException(info("Illegal syntax: `" + (char) ch + '`'));
}

if (ch != '}') {
return false;
}
comma = false;

int offset = this.offset;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
return true;
}

ch = bytes[offset];
byte[] bytes = this.bytes;

ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
offset++;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset];
ch = bytes[offset++];
}

if (ch == ',') {
comma = true;
ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
if (offset >= end) {
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset++];
}
}

this.offset = offset + 1;
this.ch = (char) (ch & 0xFF);
this.offset = offset;

while (this.ch == '/' && this.offset < bytes.length && bytes[this.offset] == '/') {
skipLineComment();
}

return true;
}

Expand Down Expand Up @@ -203,91 +214,86 @@ public final boolean nextIfMatch(char m) {

@Override
public final boolean nextIfArrayStart() {
final byte[] bytes = this.bytes;
int offset = this.offset;
int ch = this.ch;
if (ch != '[') {
return false;
}

int offset = this.offset;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
return true;
}

ch = bytes[offset];
byte[] bytes = this.bytes;

ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
offset++;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset];
ch = bytes[offset++];
}

this.offset = offset + 1;
this.ch = (char) (ch & 0xFF);
this.offset = offset;

while (this.ch == '/' && this.offset < bytes.length && bytes[this.offset] == '/') {
skipLineComment();
}

return true;
}

@Override
public final boolean nextIfArrayEnd() {
final byte[] bytes = this.bytes;
int offset = this.offset;
int ch = this.ch;
if (ch == '}' || ch == EOI) {
throw new JSONException(info());
throw new JSONException(info("Illegal syntax: `" + (char) ch + '`'));
}

if (ch != ']') {
return false;
}

int offset = this.offset;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
return true;
}

ch = bytes[offset];
byte[] bytes = this.bytes;

ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
offset++;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset];
ch = bytes[offset++];
}

if (ch == ',') {
this.comma = true;
ch = bytes[++offset];
comma = true;
ch = bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
offset++;
if (offset >= end) {
this.offset = offset;
this.ch = EOI;
this.offset = offset;
return true;
}
ch = bytes[offset];
ch = bytes[offset++];
}
}

this.offset = offset + 1;
this.ch = (char) (ch & 0xFF);
this.offset = offset;

while (this.ch == '/' && this.offset < bytes.length && bytes[this.offset] == '/') {
skipLineComment();
}

return true;
}

Expand Down
Loading