fix(c4): escape double-quotes in rendered PlantUML labels/descriptions - #11
Open
nightscape wants to merge 1 commit into
Open
nightscape wants to merge 1 commit into
nightscape wants to merge 1 commit into
Conversation
C4/PlantUML macro arguments are double-quoted and have no escape sequence for an embedded `"`. A description or label drawn from a Rust doc comment that itself contains a quote — e.g. `Typed entity name (e.g. "block", "document")` — was interpolated verbatim into `Component(...)`, so the inner quote closed the string early and corrupted the diagram. Add an `escape_label()` helper that replaces `"` with `'` and flattens newlines to spaces, and route every user-derived field (name, pattern, description, relationship label/protocol) through it in both the container and component generators. - Tests: helper unit test + a component-render test proving a quoted description no longer breaks the emitted string. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens PlantUML/C4 diagram generation by sanitizing user-provided labels/descriptions so embedded quotes/newlines don’t corrupt the generated .puml syntax.
Changes:
- Escape container/component names, patterns, descriptions, and relationship labels/protocols before embedding them in double-quoted PlantUML arguments.
- Add
escape_labelhelper to normalize quotes/newlines for PlantUML safety. - Add unit tests covering quote/newline escaping and a regression test that writes a component diagram to disk.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+184
to
+187
| let dir = std::env::temp_dir().join("archidoc_escape_test"); | ||
| std::fs::create_dir_all(&dir).unwrap(); | ||
| generate_component(&dir, &ir); | ||
| let out = std::fs::read_to_string(dir.join("c4-component.puml")).unwrap(); |
Comment on lines
111
to
+115
| "Rel({}, {}, \"{}\", \"{}\")\n", | ||
| from_id, to_id, rel.label, rel.protocol | ||
| from_id, | ||
| to_id, | ||
| escape_label(&rel.label), | ||
| escape_label(&rel.protocol) |
nightscape
added a commit
to nightscape/archidoc
that referenced
this pull request
Jun 14, 2026
Applies the escape_label() fix from PR GitSmart86#11 across dev's full generator set: container (incl. layer grouping + System_Ext), context, component, and code diagrams. Every user-derived field (name, pattern, description, relationship label/protocol, code-element name/kind) is routed through escape_label() so doc comments containing `"` or newlines no longer corrupt the rendered diagram. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
C4/PlantUML macro arguments are double-quoted and have no escape sequence for an embedded
". When a component description or relationship label is drawn from a Rust doc comment that itself contains a quote, the quote is interpolated verbatim into the rendered macro call and closes the string early, corrupting the diagram.Real example — a doc comment
/// Typed entity name (e.g. "block", "document")renders as:The
"block"quotes terminate the description argument prematurely.Fix
Add an
escape_label()helper that replaces"with'and flattens newlines to spaces, and route every user-derived field (name, pattern, description, relationship label/protocol) through it in both the container and component generators.Tests
escape_label_neutralizes_quotes_and_newlines— unit test of the helper.component_description_with_quotes_does_not_break_the_string— renders a component whose description contains quotes and asserts the emittedComponent(...)line is well-formed.cargo test --workspaceis green (the 6 pre-existingpolyglot_detection_testfailures are unrelated and fail onmaintoo).🤖 Generated with Claude Code