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

Return more-specific error when input might be application/json-seq #3191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/jv_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ static pfunc check_literal(struct jv_parser* p) {
case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
case '\'':
return "Invalid string literal; expected \", but got '";
case 0x1e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@wader wader Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the check can/could be in the scan function somewhere after we know p->flags & JV_PARSE_SEQ is not set to keep it closer to the rest of the seq parsing code? or would that affect what input errors it would detect?

I would be good if @nicowilliams (author of the rfc btw!) could have a look

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't even see that sorry, still finding my way around the code base. I'll do some more experimentation.

Ideally, I'd like to just autodetect the RS and switch it to parsing JSON-SEQ but not sure how feasible that is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't even see that sorry, still finding my way around the code base. I'll do some more experimentation.

👍 no worries

Ideally, I'd like to just autodetect the RS and switch it to parsing JSON-SEQ but not sure how feasible that is.

No that familiar with the input code so don't know either. Just error out with nicer error message is good start i think.

return "Record Separator (RS) detected, this might be application/json-seq. Try using the --seq option.";
case 'n':
// if it starts with 'n', it could be a literal "nan"
if (p->tokenbuf[1] == 'u') {
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,10 @@ try fromjson catch .
"{'a': 123}"
"Invalid string literal; expected \", but got ' at line 1, column 5 (while parsing '{'a': 123}')"

try fromjson catch .
"\u001e{\"a\": 123}"
"Record Separator (RS) detected, this might be application/json-seq. Try using the --seq option. at line 1, column 2 (while parsing '\u001e{\"a\": 123}')"

# ltrimstr/1 rtrimstr/1 don't leak on invalid input #2977

try ltrimstr(1) catch "x", try rtrimstr(1) catch "x" | "ok"
Expand Down
Loading