fix: use byte-safe indexing in style encapsulation to prevent UTF-8 panics#248
Open
BenjaminDobler wants to merge 2 commits intovoidzero-dev:mainfrom
Open
fix: use byte-safe indexing in style encapsulation to prevent UTF-8 panics#248BenjaminDobler wants to merge 2 commits intovoidzero-dev:mainfrom
BenjaminDobler wants to merge 2 commits intovoidzero-dev:mainfrom
Conversation
…-8 panics Several functions in the style encapsulation module used char indices to slice UTF-8 strings, causing panics on selectors containing multibyte characters (e.g. `ü`, `é`, `─`). This fixes `split_by_combinators`, `find_pseudo_element_start`, `find_pseudo_class_start`, `find_matching_paren`, and `try_scope_pseudo_function_with_context` to use either `char_indices()` or byte-level scanning for ASCII-only delimiters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merged upstream's addition of \n, \t, \r to combinator matching with our byte-safe char_indices() indexing fix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
ü,é,─box-drawing chars in comments)encapsulation.rsused char indices to slice&str, which panics when a char index falls inside a multibyte UTF-8 sequencesplit_by_combinators,find_pseudo_element_start,find_pseudo_class_start: switched fromchars().collect()tochar_indices().collect()so string slicing uses byte offsetstry_scope_pseudo_function_with_context,find_matching_paren: switched fromchars[i]tobytes[i]matching since(/)are ASCII and UTF-8 guarantees ASCII bytes never appear as continuation bytesReproduction
Any SCSS file with multibyte UTF-8 characters processed through style encapsulation triggers the panic:
Test plan
cargo testpassescargo fmt --checkpasses🤖 Generated with Claude Code