Skip to content

Strip all leading BOMs, not just the first (#390) - #391

Open
youdie006 wants to merge 1 commit into
go-ini:mainfrom
youdie006:fix/390-multiple-bom
Open

Strip all leading BOMs, not just the first (#390)#391
youdie006 wants to merge 1 commit into
go-ini:mainfrom
youdie006:fix/390-multiple-bom

Conversation

@youdie006

Copy link
Copy Markdown

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:

key-value delimiter not found: [author]

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-BOM subtest to TestBOM that loads \xEF\xBB\xBF\xEF\xBB\xBF[author]\nE-MAIL = [email protected] and asserts it parses. Red-green verified with go test: before the fix it fails with key-value delimiter not found: [author]; after, it parses correctly. The full suite and go vet pass; gofmt is clean.

(*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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ini-files with two BOMs confuse the parser

1 participant