Skip to content
Myr

Skip to the next RS after a parse error in --seq mode (#3654)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Michiel van Slobbe · committed by GitHub · parent 611c575 · Browse files · 2 files+9 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−1 removed

  • tests:+8 added−0 removed
  • other:+1 added−1 removed

2 files+9 added−1 removed

modified:src/jv_parse.c+1 added-1 removed
783 unmodified lines
784 } else if (msg) {785 jv_free(value);786 if (ch != '\036' && (p->flags & JV_PARSE_SEQ)) {787 // Skip to the next RS788 p->st = JV_PARSER_WAITING_FOR_RS;788 value = make_error(p, "%s at line %d, column %d (need RS to resync)", msg, p->line, p->column);789 parser_reset(p);790 p->st = JV_PARSER_WAITING_FOR_RS;791 return value;792 }793 value = make_error(p, "%s at line %d, column %d", msg, p->line, p->column);794 parser_reset(p);
104 unmodified lines
modified:tests/shtest+8 added
85 unmodified lines
86EOF87printf '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/out88cmp $d/out $d/expected8990# A syntax error skips the rest of the text, up to the next RS91cat > $d/expected <<EOF92jq: ignoring parse error: Invalid numeric literal at line 1, column 8 (need RS to resync)93jq: ignoring parse error: Unmatched '}' at line 2, column 5 (need RS to resync)94EOF95printf '\036{"a":x,"b":7}\n\036[1,}2\n\0363\n' | $VALGRIND $Q $JQ -ces --seq '. == [3]' > /dev/null 2> $d/out96cmp $d/out $d/expected9798# Note that here jq sees no inputs at all but it still succeeds because99# --seq ignores parse errors100cat > $d/expected <<EOF101jq: ignoring parse error: Unfinished abandoned text at EOF at line 1, column 4
906 unmodified lines