When validating JSON/JSON5 containing raw Unicode escape sequences (such as \u2014), the lint diagnostics for subsequent errors in the document calculate character ranges incorrectly. When the calculated range becomes out-of-bounds due to offset drift, CodeMirror falls back to placing the error indicator at Line 1, Column 1.
To Reproduce
- Configure
codemirror-json-schema with json5Schema(schema).
- Insert a document containing a
\uXXXX escape sequence on an early line, followed by a syntax or schema error later in the file:
{
"title": "Config Sample",
"description": "Unicode character \u2014 here causes position drift",
"settings": {
"enabled": true,
"timeout": 3000
// Intentionally missing comma or syntax error here
"retries": 3
}
}
Expected behavior
The error indicator (red gutter dot / underline) should highlight line 7 where the syntax error occurs.
Actual behavior
The error indicator jumps to Line 1, Column 1.
Root Cause Analysis
The raw editor text contains \u2014 as 6 physical characters (, u, 2, 0, 1, 4), but the underlying AST parser unescapes it into a single character (—), spanning 1 character unit. Every \uXXXX sequence shifts the AST node offsets by 5 characters. When codemirror-json-schema maps the error back to CodeMirror ranges, the position calculation becomes invalid/negative and defaults to index 0.
When validating JSON/JSON5 containing raw Unicode escape sequences (such as
\u2014), the lint diagnostics for subsequent errors in the document calculate character ranges incorrectly. When the calculated range becomes out-of-bounds due to offset drift, CodeMirror falls back to placing the error indicator at Line 1, Column 1.To Reproduce
codemirror-json-schemawithjson5Schema(schema).\uXXXXescape sequence on an early line, followed by a syntax or schema error later in the file:Expected behavior
The error indicator (red gutter dot / underline) should highlight line 7 where the syntax error occurs.
Actual behavior
The error indicator jumps to Line 1, Column 1.
Root Cause Analysis
The raw editor text contains \u2014 as 6 physical characters (, u, 2, 0, 1, 4), but the underlying AST parser unescapes it into a single character (—), spanning 1 character unit. Every \uXXXX sequence shifts the AST node offsets by 5 characters. When codemirror-json-schema maps the error back to CodeMirror ranges, the position calculation becomes invalid/negative and defaults to index 0.