Skip to content

fix: use char count instead of byte length for json_schema spans - #164

Open
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/json-schema-non-ascii-panic
Open

fix: use char count instead of byte length for json_schema spans#164
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/json-schema-non-ascii-panic

Conversation

@Kubudak90

Copy link
Copy Markdown

Fixes #100.

The json_schema lint was using source.len() (byte length) for annotation spans, which causes a panic when the source contains non-ASCII characters (e.g., Unicode in CSL-JSON citations). The annotate-snippets crate expects character counts, not byte lengths.

Changes:

  • Changed source.len() to source.chars().count() in json_schema.rs
  • Added test cases for non-ASCII input in CSL-JSON code blocks

Root cause: When a code block contains multi-byte UTF-8 characters, source.len() returns the byte length (e.g., 99 bytes for 98 characters), but the annotation system expects character indices. This mismatch triggers the panic:

SourceAnnotation range `(0, 99)` is bigger than source length `98`

All tests pass.

The  lint used  (byte length)
for annotation spans, but  expects character
offsets. This caused incorrect diagnostics and potential panics
when the markdown source contained multi-byte UTF-8 characters
before the code block.

Fix by using  instead, matching the fix
already applied to  in ethereum#151.

Closes ethereum#100 (same root cause, different lint).
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.

1 participant