-
Notifications
You must be signed in to change notification settings - Fork 324
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
Handle closing flow sequence after explicit key #295
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[{?}]
and [{?}]]
are similar. Can you verify it fixes those?
Tests should probably be added.
Those are not affected by the code and work like expected already.
I will add tests to the yaml-test-suite. |
Oh you are right. Misread again. |
The fix in yaml#295 was not correct. # cat a.yaml [?] # Before % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': run-loader: loader.c:470: yaml_parser_load_sequence_end: Assertion `parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE' failed. [1] 21446 IOT instruction (core dumped) ./tests/run-loader a.yaml # After % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} =VAL : =VAL : -MAP -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': SUCCESS (1 documents)
The fix in yaml#295 was not correct. # cat a.yaml --- [?] # Before % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': run-loader: loader.c:470: yaml_parser_load_sequence_end: Assertion `parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE' failed. [1] 21446 IOT instruction (core dumped) ./tests/run-loader a.yaml # After % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} =VAL : =VAL : -MAP -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': SUCCESS (1 documents)
The fix in yaml#295 was not correct. # cat a.yaml --- [?] # Before % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': run-loader: loader.c:470: yaml_parser_load_sequence_end: Assertion `parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE' failed. [1] 21446 IOT instruction (core dumped) ./tests/run-loader a.yaml # After % ./tests/run-parser-test-suite --flow keep < a.yaml +STR +DOC --- +SEQ [] +MAP {} =VAL : =VAL : -MAP -SEQ -DOC -STR % ./tests/run-loader a.yaml [1] Loading 'a.yaml': SUCCESS (1 documents)
This PR caused a problem, and is now fixed with #296 |
Currently after an explicit flow key '?' in a flow sequence, an immediately following closing ] is ignored by the parser:
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.