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
mermaid-text: flowchart parser panics on a node labelled [/] or [\] #55
At 83bc806 (mermaid-text 0.57.4), a flowchart node whose bracket body is a single / or \ panics the parser instead of returning an error:
flowchart LR
A[\]
Loading
thread 'main' panicked at crates/mermaid-text/src/parser/flowchart.rs:968:29:
byte range starts at 2 but ends at 1
graph TD\n A[/] panics the same way at line 958.
The slanted-shape branches test rest.starts_with("[\\") and rest.ends_with("\\]") (and the / variants), then slice rest[2..rest.len() - 2]. With rest == "[\\]", three characters satisfy both two-character tests, so the slice runs from 2 to 1. Only the two same-slash shapes can overlap like that, [/x/] (line 958) and [\x\] (line 968). The mixed ones need four characters to match both ends, which gives an empty slice rather than a backwards one.
A guard like rest.len() >= 4 on those branches would let these fall through to the plain rectangle, or to an error. Either is fine for us. The panic is what matters: it aborts any caller that renders untrusted source. We now catch it on our side, but other users of the crate may not.
Activity