You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] mermaid-text: classDiagram panics on non-ASCII lines (byte index is not a char boundary) #50
mermaid_text::render panics on a classDiagram whose lines contain multi-byte characters (CJK, Cyrillic, …), e.g. a plain relation 動物 <|-- 犬.
The class parser still has its own copy of the keyword-strip helper, strip_keyword_prefix_ci (crates/mermaid-text/src/parser/class.rs:619), which slices line[..kw.len()] at a byte index. It looks like the one copy the #29 audit (0.56.1) didn't catch: gantt/timeline/journey were routed to parser::common::strip_keyword_prefix then, but this _ci-suffixed one in class.rs was left behind.
class 動物 and 犬 --|> 動物 happen not to panic, because none of the probed keyword lengths (class, direction, note, link, click, namespace) lands inside a character there.
Expected Behavior
The diagram renders like its ASCII spelling. For the unsupported colon shorthand, render returns the usual Err.
Actual Behavior
thread 'main' panicked at crates/mermaid-text/src/parser/class.rs:622:16:
byte index 4 is not a char boundary; it is inside '物' (bytes 3..6) of `動物 <|-- 犬`
I ran into this in cosentty, a terminal viewer for Cosense (formerly Scrapbox, a wiki service popular in Japan). It renders Mermaid blocks with mermaid-text and wraps the call in catch_unwind for now. I also fed CJK input to every diagram type the crate parses (30 sources); this was the only panic.
A small PR with regression tests follows. I used an AI coding assistant for the investigation and drafting; the repro and the diff were checked locally.
Fixed on master by #51. Non-ASCII class names now use the shared UTF-8-safe keyword helper. The accompanying review also fixed Unicode whitespace in class methods/ER relationships and malformed class-method parentheses, with exact parser regressions.
Thank you @worldnine for the original fix and reproductions. Your authored commit is preserved, and both changelogs credit your contribution. The fixes passed local stable/Rust 1.92 workspace tests and validation gates. This closes the source issue; no release has been published yet.
Activity
leboiko commentedon Oct 13, 2026
Fixed on master by #51. Non-ASCII class names now use the shared UTF-8-safe keyword helper. The accompanying review also fixed Unicode whitespace in class methods/ER relationships and malformed class-method parentheses, with exact parser regressions.
Thank you @worldnine for the original fix and reproductions. Your authored commit is preserved, and both changelogs credit your contribution. The fixes passed local stable/Rust 1.92 workspace tests and validation gates. This closes the source issue; no release has been published yet.
fix(mermaid-text): route classDiagram keyword probe through the UTF-8…