Skip to content

Commit

Permalink
Handle closing flow sequence after explicit key
Browse files Browse the repository at this point in the history
Currently after an explicit flow key '?' in a flow sequence, an immediately
following closing ] is ignored by the parser:

    % echo '[ ? ]' | ./tests/run-parser-test-suite --flow keep
    +STR
    +DOC
    +SEQ []
    +MAP {}
    =VAL :
    =VAL :
    -MAP
    Parse error: did not find expected ',' or ']'
    Line: 2 Column: 1
    % echo '[ ? ] ]' | ./tests/run-parser-test-suite --flow keep
    +STR
    +DOC
    +SEQ []
    +MAP {}
    =VAL :
    =VAL :
    -MAP
    -SEQ
    -DOC
    -STR

It is read correctly by the scanner as a YAML_FLOW_SEQUENCE_END_TOKEN, and
the flow_level is decreased. Then it is passed to the parser where it gets
ignored.
This leads to invalid YAML being accepted, and valid YAML resulting in an
error.

Also the flow_level is incorrectly decreased, so you can nest sequences
like that without running in to the MAX_NESTING_LEVEL.
  • Loading branch information
perlpunk committed May 6, 2024
1 parent abd744e commit 588eabf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,13 @@ yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser,
return 0;
return yaml_parser_parse_node(parser, event, 0, 0);
}
else if (token->type == YAML_FLOW_SEQUENCE_END_TOKEN) {
parser->state = POP(parser, parser->states);
(void)POP(parser, parser->marks);
SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->end_mark);
SKIP_TOKEN(parser);
return 1;
}
else {
yaml_mark_t mark = token->end_mark;
SKIP_TOKEN(parser);
Expand Down

0 comments on commit 588eabf

Please sign in to comment.