Skip to content

Return friendly error when loading JSON has a leading UTF‑8 BOM#7488

Merged
laurmaedje merged 3 commits intotypst:mainfrom
3w36zj6:feature/return-friendly-error-when-loading-json-has-a-leading-utf-8-bom
Dec 1, 2025
Merged

Return friendly error when loading JSON has a leading UTF‑8 BOM#7488
laurmaedje merged 3 commits intotypst:mainfrom
3w36zj6:feature/return-friendly-error-when-loading-json-has-a-leading-utf-8-bom

Conversation

@3w36zj6
Copy link
Contributor

@3w36zj6 3w36zj6 commented Nov 29, 2025

close #5440
close #3157

This pull request improves the handling of JSON files in the loading library by adding explicit detection and error reporting for files that start with a UTF-8 Byte Order Mark (BOM), which is not allowed by the JSON specification.

Although the JSON specification does not allow BOM, we could consider a more forgiving approach that removes the BOM when encountering BOM-prefixed JSON files. However, in my opinion, most major programming languages throw an error for JSON files with a BOM. To maintain consistent and clear behavior, this PR opts to throw a friendly error message in such cases.

@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Dec 1, 2025
@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Dec 1, 2025
@laurmaedje laurmaedje enabled auto-merge December 1, 2025 10:14
@laurmaedje
Copy link
Member

Thanks!

@laurmaedje laurmaedje added this pull request to the merge queue Dec 1, 2025
Merged via the queue into typst:main with commit 5740424 Dec 1, 2025
8 checks passed
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.

Hint when text file encoding is not standard UTF-8 json(path) does not support UTF8 with BOM

2 participants