Skip to the next RS after a parse error in --seq mode (#3654)
In --seq mode, a parse error was reported as "need RS to resync", but parsing continued in the middle of the broken text, so fragments of it were reported as more errors or output as values. Set the parser state to wait for the next RS after resetting the parser, instead of before, so that the rest of the broken text is skipped as RFC 7464 recommends.
This commit is contained in:
1 parent
611c575a97
commit
80fc7a169d
2 files changed
+9
-1
No files matched your search
+1
-1
@@ -785,9 +785,9 @@ jv jv_parser_next(struct jv_parser* p) {
|
||||
jv_free(value);
|
||||
if (ch != '\036' && (p->flags & JV_PARSE_SEQ)) {
|
||||
// Skip to the next RS
|
||||
p->st = JV_PARSER_WAITING_FOR_RS;
|
||||
value = make_error(p, "%s at line %d, column %d (need RS to resync)", msg, p->line, p->column);
|
||||
parser_reset(p);
|
||||
p->st = JV_PARSER_WAITING_FOR_RS;
|
||||
return value;
|
||||
}
|
||||
value = make_error(p, "%s at line %d, column %d", msg, p->line, p->column);
|
||||
|
||||
@@ -87,6 +87,14 @@ EOF
|
||||
printf '1\0362 3\n[0,1\036[4,5]true"ab"{"c":4\036{}{"d":5,"e":6"false\n\036null'|$VALGRIND $Q $JQ -ces --seq '. == [2,3,[4,5],true,"ab",{},null]' > /dev/null 2> $d/out
|
||||
cmp $d/out $d/expected
|
||||
|
||||
# A syntax error skips the rest of the text, up to the next RS
|
||||
cat > $d/expected <<EOF
|
||||
jq: ignoring parse error: Invalid numeric literal at line 1, column 8 (need RS to resync)
|
||||
jq: ignoring parse error: Unmatched '}' at line 2, column 5 (need RS to resync)
|
||||
EOF
|
||||
printf '\036{"a":x,"b":7}\n\036[1,}2\n\0363\n' | $VALGRIND $Q $JQ -ces --seq '. == [3]' > /dev/null 2> $d/out
|
||||
cmp $d/out $d/expected
|
||||
|
||||
# Note that here jq sees no inputs at all but it still succeeds because
|
||||
# --seq ignores parse errors
|
||||
cat > $d/expected <<EOF
|
||||
|
||||
Reference in new issue
Block a user