mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 01:44:15 +00:00
`EscapeBodyTextWithWbr` iterates `text.grapheme_indices(true)`, so `i` is the start of a grapheme cluster, but the `_`/`:` word-break arm sliced at `i + 1` -- assuming a cluster containing `_` or `:` is exactly one byte long. UAX#29 GB9b joins a `Prepend`-class character (U+0600-U+0605, U+0D4E, U+111C2, ...) with the character that follows it, so a cluster can start with a multi-byte character and still contain `_`. `i + 1` then lands inside that character and `str` indexing panics. U+0D4E is `XID_Continue`, so this is reachable from an item name rustc accepts, e.g. `pub struct abc<U+0D4E>_defgh;`, and rustdoc ICEs instead of documenting the crate. Break after the whole cluster (`i + s.len()`) instead. The adjacent CamelCase arm already slices at `i`, which is always a cluster boundary, so it is unaffected. This also stops the `<wbr>` from being inserted between `_` and a combining mark that trails it, which split a grapheme cluster without panicking.