From 80fc7a169d3a3942a07f587abc4346d119fc525d Mon Sep 17 00:00:00 2001 From: Michiel van Slobbe Date: Mon, 12 Oct 2026 06:40:40 +0200 Subject: [PATCH] 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. --- src/jv_parse.c | 2 +- tests/shtest | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/jv_parse.c b/src/jv_parse.c index fe780540..649cfae4 100644 --- a/src/jv_parse.c +++ b/src/jv_parse.c @@ -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); diff --git a/tests/shtest b/tests/shtest index 8f3e0f63..9b27dc2f 100755 --- a/tests/shtest +++ b/tests/shtest @@ -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 < /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 <