Repository navigation
fix(mermaid): escape the punctuation a sequence diagram reads as syntax - #169
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSequence diagram generation now escapes syntax-sensitive participant names, messages, notes, and control-block descriptions. Tests and edge-case fixtures cover punctuation, entity-like sequences, preserved percent and hash forms, emoji, and Japanese text. ChangesSequence diagram escaping
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment has been minimized.
This comment has been minimized.
A sequence diagram takes no quoted text anywhere, so a message, a note, a block description and a participant name all go out bare, and each loses a different set of characters. In the text of a diagram a semicolon ends the statement and loses the whole picture, and a "#" opens a comment: "deploy #2 of 3" reached the drawing as "deploy" and nothing said so. A participant name loses more. A semicolon ends the statement there too; a colon separates a name from the message after it and a comma separates one name from the next; an angle bracket opens the arrow syntax. A hyphen is the start of every arrow, so "web-server" could be declared and then never sent a message. A "%%" opens a comment on the message line and drops the message without a word. A parenthesis is safe on its own and a pair is not, so both are written out: an unmatched one is not a name anybody writes, and the pair is what "Deploy (prod)" has. Each is written as the entity form mermaid decodes, and a name is escaped identically where it is declared and where a message refers to it, so the two still match. A test pins that. Three things are deliberately left alone: a "#" in a participant name, a lone "%" anywhere, and the comma between two participants a note is placed over, which is the syntax that says the note spans both and cannot be told apart from one name holding a comma. The sequence entry in doc/edgecase goes from six punctuation marks to the full set. No golden file moves. Refs #146
11e990d to
f3d2194
Compare
Code Metrics Report
Details | | main (d06f2bb) | #169 (528a9e4) | +/- |
|---------------------|----------------|----------------|-------|
- | Coverage | 96.4% | 96.4% | -0.1% |
| Files | 77 | 78 | +1 |
| Lines | 3263 | 3285 | +22 |
+ | Covered | 3148 | 3169 | +21 |
+ | Test Execution Time | 10s | 9s | -1s |Code coverage of files in pull request scope (99.0% → 98.4%)
Reported by octocov |
Refs #146 — one subpackage per pull request. This is
sequence, and it has the widest spread of the set because a sequence diagram takes no quoted text anywhere.Two escape sets, measured one character at a time
Message, note, block description —
#;;#deploy #2 of 3reaches the drawing asdeploy, silentlyParticipant name —
;:,<>-%%();:,<>-web-servercould be declared but never sent a message%%()A name is escaped identically where it is declared and where a message refers to it, so the two still match. There is a test for exactly that, since getting it wrong would silently create a second participant.
Deliberately left alone
#in a participant name — safe there, unlike in message text.%anywhere — only a run opens a comment, so50% trafficis untouched.NoteOver("Alice,Bob", …)is documented mermaid syntax for a note across both, and this package cannot tell it apart from one name holding a comma. Tested, and called out in the code.On the parentheses: a single unmatched
(renders today, so escaping it does change working output. An unmatched parenthesis is not a name anybody writes, and the matched pair —Deploy (prod)— is broken today. The drawn text is identical either way.Verification
go test ./...passes with no golden file changed;golangci-lint run ./...reports 0 issues.mermaid/sequencecoverage 98.7%.sequenceentry indoc/edgecase/main.gogoes from"'#[]+emoji+Japanese+*-|to the full probe set, and the document is regenerated. Every committed diagram renders: 64 blocks, 0 failed.Summary by CodeRabbit
<br/>breaks while excluding unsupported line breaks.