Repository navigation
fix: ignore a UTF-8 BOM at the start of the input in decode - #325
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
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.
An ini file saved as "UTF-8 with BOM" (Notepad's default on older Windows, and an option in most editors) loses its first section header:
fs.readFileSync(file, 'utf8')keeps the BOM, so the first line is[section], which doesn't match the^\[section pattern. It then falls through to the key branch, andunsafe()trims the BOM (JStrim()treats U+FEFF as whitespace), which is why it comes back as a key named[section]. Every key until the next header then ends up at the top level. Keys and comments on the first line are not affected for the same reason, only section headers.decodenow drops a leading U+FEFF before splitting lines.test/bom.jscovers a BOM before a section, before CRLF sections, and before a top-level key; it fails without the change.npm testpasses, with lint and 100% coverage.