fix: use character count for regex lint spans (fixes #100) - #165
Open
Kubudak90 wants to merge 1 commit into
Open
fix: use character count for regex lint spans (fixes #100)#165Kubudak90 wants to merge 1 commit into
Kubudak90 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The generic
Regexlint ineipw-lint/src/lints/markdown/regex.rsuses 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:This is the same root cause as #100, but affects all markdown lints that use the
Regexstruct (e.g.,markdown-link-first,markdown-link-status,markdown-rel-links, etc.), not justmarkdown-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 deletionsVerification
cargo testpassesjson_schema.rs(PRs fix: prevent panic in markdown-json-cite with non-ASCII input #162/fix: use char count instead of byte length for json_schema spans #164)Fixes #100