Skip to content

fix: prevent panic on multi-byte UTF-8 in cheatsheet prefix lines#1025

Open
kimjune01 wants to merge 1 commit into
denisidoro:masterfrom
kimjune01:fix/parser-panic-multibyte-prefix
Open

fix: prevent panic on multi-byte UTF-8 in cheatsheet prefix lines#1025
kimjune01 wants to merge 1 commit into
denisidoro:masterfrom
kimjune01:fix/parser-panic-multibyte-prefix

Conversation

@kimjune01

Copy link
Copy Markdown

Fixes #917.

without_prefix assumed the prefix character plus separator always occupies exactly 2 bytes (line[2..]). When the separator is a non-breaking space (\u{a0}, 2 bytes in UTF-8), byte index 2 falls inside the multi-byte character and panics:

thread 'main' panicked at 'byte index 2 is not a char boundary; it is inside '\u{a0}''

Skip only the 1-byte ASCII prefix char (#, %, @) and let trim() handle any whitespace separator, including multi-byte whitespace. Same idea applied to without_first.

Tests cover the exact input from the bug report, normal ASCII prefixes, and edge cases (empty, prefix-only).

without_prefix used byte-indexing (line[2..]) which panics when the
separator after #/%/@ is a multi-byte character like non-breaking
space (\u{a0}). Skip only the 1-byte ASCII prefix and let trim()
handle all whitespace variants.

Also fix dormant panic in without_first for multi-byte first chars.

Closes denisidoro#917
@kimjune01
kimjune01 requested a review from denisidoro as a code owner May 9, 2026 17:15
@jackandroselv

jackandroselv commented May 9, 2026 via email

Copy link
Copy Markdown

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.

thread 'main' panicked on specific cheatsheet

3 participants