Skip to content

fix: use character count for regex lint spans (fixes #100) - #165

Open
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/regex-utf8-byte-to-char-offsets
Open

fix: use character count for regex lint spans (fixes #100)#165
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/regex-utf8-byte-to-char-offsets

Conversation

@Kubudak90

Copy link
Copy Markdown

Problem
The generic Regex lint in eipw-lint/src/lints/markdown/regex.rs uses byte offsets directly when creating annotation spans. When the source text contains multi-byte UTF-8 characters (e.g., emojis, non-ASCII text), the byte offset exceeds the character count expected by the annotation framework, causing a panic:

SourceAnnotation range is bigger than source length

This is the same root cause as #100, but affects all markdown lints that use the Regex struct (e.g., markdown-link-first, markdown-link-status, markdown-rel-links, etc.), not just markdown-json-cite.

Fix
Convert byte offsets to character counts using source[..start].chars().count() before creating annotation spans, matching how the linting framework expects positions.

Files changed

  • eipw-lint/src/lints/markdown/regex.rs: 6 insertions, 2 deletions

Verification

Fixes #100

The Regex lint was using byte offsets directly for annotation spans,
which caused panics when non-ASCII characters appeared in the source.
Multi-byte UTF-8 characters made the byte offset exceed the character
count, triggering 'SourceAnnotation range is bigger than source length'.

This fix converts byte offsets to character counts before creating
annotation spans, matching how the linting framework expects positions.

Fixes ethereum#100
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