fix(jsonc-parser): strip UTF-8 BOM before parsing to fix Windows "InvalidSymbol at offset 0" errors

Windows editors often save UTF-8 files with a BOM (Byte Order Mark: \uFEFF).
When this is present, jsonc-parser reports InvalidSymbol at offset 0 because
the BOM is not valid JSON/JSONC syntax.

This commit strips the BOM before parsing, fixing issues #3164 where Windows
users report their opencode.jsonc file fails to parse even though it appears
to start with a valid '{' character.

Fixes: #3164
Co-authored-by: Jobdori <agent@yeongyu.kim>
This commit is contained in:
YeonGyu-Kim
2026-04-07 14:48:30 +09:00
parent 3e8fd5ff18
commit daae6ed05b
2 changed files with 30 additions and 0 deletions
+3
View File
@@ -10,6 +10,9 @@ export interface JsoncParseResult<T> {
}
export function parseJsonc<T = unknown>(content: string): T {
// Strip UTF-8 BOM if present (Windows UTF-8 with BOM files)
content = content.replace(/^\uFEFF/, "")
const errors: ParseError[] = []
const result = parse(content, errors, {
allowTrailingComma: true,