Skip to content

[JSON5] Validation error diagnostic range falls back to line 1 when string contains Unicode escapes (\uXXXX #171

Description

@OmPr366

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

  1. Configure codemirror-json-schema with json5Schema(schema).
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions