Skip to content

Doc-Comment Indent Stripping Splits a UTF-8 Codepoint #800

Description

@InsertCreativityHere

comments/grammar.rs:105–125: the common leading-whitespace amount is computed as a byte offset via str::find, min'd across lines, then applied to every line with replace_range(..common, "").

If lines have different-byte-width leading whitespace (an ASCII space on one line, a multi-byte Unicode space like NBSP U+00A0 on another — a common copy-paste artifact), the byte offset lands mid-codepoint → panic end of range should be a character boundary. Parsed at construction time, before validation:

Reproduction

printf '/// a\n///\xc2\xa0b\nstruct S {}\n' > nbsp.slice && ./slicec nbsp.slice --dry-run

It's also a latent correctness bug (mixed indentation stripped by the wrong amount).

Fix

Measure and strip in chars, not bytes: char_indices().nth(common).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

slicecRelated to the 'slicec' crate

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions