Strip all leading BOMs, not just the first (#390) - #391
Open
youdie006 wants to merge 1 commit into
Open
Conversation
(*parser).BOM() removed at most one leading byte-order mark, so a file that begins with two BOMs (e.g. a tool prepending a BOM to already-BOM'd content) left the second BOM on the next line. That line no longer began with [, # or ; and had no key-value delimiter, so the parser aborted with a misleading "key-value delimiter not found" error on otherwise valid content. Loop the BOM detection until no BOM prefix remains. Fixes go-ini#390
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 #390.
Problem
(*parser).BOM()removes at most one leading byte-order mark. When a file begins with two BOMs (e.g. tooling that prepends a BOM to already-BOM'd content), only the first is stripped. The main line loop then reads[author](or# comment), which no longer begins with[/#/;, so section/comment detection misses it, and with no=/:the parser aborts with a misleading error:Fix
Loop the BOM detection until no BOM prefix remains (UTF-8 and UTF-16 LE/BE), so all leading BOMs are stripped.
Test
Added a
multiple UTF-8-BOMsubtest toTestBOMthat loads\xEF\xBB\xBF\xEF\xBB\xBF[author]\nE-MAIL = [email protected]and asserts it parses. Red-green verified withgo test: before the fix it fails withkey-value delimiter not found: [author]; after, it parses correctly. The full suite andgo vetpass;gofmtis clean.