Skip to content

ini-files with two BOMs confuse the parser #390

Description

@klaernie

Version

v1.67.3-2-g3b7d6ad (current main branch + the reproduction test case I linked below as well)

Describe the bug

When parsing a file that contains two byte-order-marks at the start of the file, which are not followed by a valid non-comment statement, causes the parser to trip with an error like this:

key-value delimiter not found: # this line is not parsed successfully

To reproduce

I prepared a test case, based on the UTF-8-BOM.ini testcase, that cleanly reproduces the issue, so you can simply checkout my fork and run the test case.

Expected behavior

These files are out in the wild and IMHO the parser should at least be clever enough to recognize them and warn the user that their file is technically broken. One could argue that it's not the responsibility of go-ini, but I would hope that it could be tolerant enough to return the valid data it can parse, and possibly fix the error when editing a file directly.

Additional context

This has originally been reported as an issue for editorconfig-checker, which uses the editorconfig-core library, which in turn uses go-ini to parse the .editorconfig files:

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions