Skip to content

fix(c4): escape double-quotes in rendered PlantUML labels/descriptions - #11

Open
nightscape wants to merge 1 commit into
GitSmart86:mainfrom
nightscape:feat/escape-plantuml-strings
Open

nightscape wants to merge 1 commit into
GitSmart86:mainfrom
nightscape:feat/escape-plantuml-strings

Conversation

@nightscape

Copy link
Copy Markdown

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:

Component(api__EntityName, "EntityName", "enum", "Typed entity name (e.g. "block", "document")")

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 emitted Component(...) line is well-formed.

cargo test --workspace is green (the 6 pre-existing polyglot_detection_test failures are unrelated and fail on main too).

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 14, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_label helper 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>
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.

2 participants