Do not count a leading BOM as a column (#334) - #345
Open
youdie006 wants to merge 1 commit into
Open
Conversation
When the input encoding is set explicitly with yaml_parser_set_encoding, the reader does not strip a leading BOM, so the scanner skips it in yaml_parser_scan_to_next_token. SKIP() advances mark.column, so the first real token started at column 1 instead of 0, and a root-level block mapping then failed to parse with "did not find expected <document start>". Per YAML 1.2 section 5.2 a BOM is not content and must not advance the column. Reset mark.column to 0 after skipping the BOM. Add a regression test. Fixes yaml#334
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #334.
Problem
When the input encoding is set explicitly with
yaml_parser_set_encoding()(e.g.YAML_UTF8_ENCODING), the reader'sdetermine_encoding()BOM stripping is skipped, so a leading BOM reaches the scanner.yaml_parser_scan_to_next_token()skips it withSKIP(parser)— butSKIPincrementsparser->mark.column, so the first real token starts at column 1 instead of 0. A root-level block mapping then terminates at the first newline and parsing fails withdid not find expected <document start>. Per YAML 1.2 section 5.2 a BOM is not content and must not advance the column. The same input parses correctly underYAML_ANY_ENCODING(where the BOM was already stripped upstream).Fix
Reset
mark.columnto 0 after skipping the BOM, so the following token starts at column 0.Test
Added
tests/test-bom.c(registered inMakefile.amandCMakeLists.txt, followingtest-nesting): it parses"\xEF\xBB\xBF" "a: b\nc: d\n"under bothYAML_UTF8_ENCODINGandYAML_ANY_ENCODINGand asserts both fully parse the two-entry mapping. Red-green verified: before the fix the explicit-UTF-8 case fails (did not find expected <document start>), after the fix both pass. The existingtest-reader/test-nesting/test-versionstill pass, and parser-token output is byte-identical to the unmodified build acrossexamples/*.yaml(the fix only affects the BOM-at-column-0 path).