Skip to content

fix: rm BOM from file content on read - #53

Merged
chrisgrieser merged 1 commit into
chrisgrieser:mainfrom
everdro1d:bom-read-bug
Jun 30, 2026
Merged

fix: rm BOM from file content on read#53
chrisgrieser merged 1 commit into
chrisgrieser:mainfrom
everdro1d:bom-read-bug

Conversation

@everdro1d

@everdro1d everdro1d commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem statement

If a json file has utf-8 encoding, vim.json.decode will fail due to the BOM at the start. If package.json or snippet files are utf-8 encoded, it will fail to load. Resolves #52.

Proposed solution

This change removes the BOM from the file contents before attempting to decode.

function M.readAndParseJson(path)
-- ...
    -- See #52, #53. utf-8 encoded files have a BOM at the start which
	-- makes vim.json.decode fail. This removes the BOM if it exists.
    content = string.gsub(content, "^\xEF\xBB\xBF", "")
-- ...
end

AI usage disclosure

None used.

@chrisgrieser

Copy link
Copy Markdown
Owner

Could you add some explanation and/or reference the issue number in the comment? Just so it's clear for future work why that line is necessary.

Otherwise good to merge

@everdro1d
everdro1d marked this pull request as draft June 30, 2026 17:35
If a json file has utf-8 encoding vim.json.decode will fail due to the
BOM at the start.

This change removes the BOM from the file contents before attempting to
decode.

Resolves chrisgrieser#52.
@everdro1d
everdro1d marked this pull request as ready for review June 30, 2026 17:48
@chrisgrieser
chrisgrieser merged commit 77dfcaf into chrisgrieser:main Jun 30, 2026
5 checks passed
@chrisgrieser

Copy link
Copy Markdown
Owner

Thanks for the PR!

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.

[Bug]: package.json fails to load when file has utf-8 BOM

2 participants