Skip to content

internal/graph: emit DOT via structured internal/dotwriter encoder - #1065

Merged
nolanmar511 merged 1 commit into
google:mainfrom
aalexand:dot-attr-escaping
Nov 10, 2026
Merged

nolanmar511 merged 1 commit into
google:mainfrom
aalexand:dot-attr-escaping

Conversation

@aalexand

Copy link
Copy Markdown
Collaborator

Previously, ComposeDot built DOT statements via ad-hoc fmt.Sprintf and fmt.Fprintf calls into an embedded io.Writer, relying on each call site to remember escapeForDot. Several profile- or caller-supplied strings were interpolated without escaping, including sample label and numeric tag names in nodelets, FormatValue output (which incorporates custom SampleType.Unit strings), LegendURL, and DotNodeAttributes.URL/Shape, allowing double quotes in profile data to break out of quoted DOT strings and inject arbitrary DOT attributes (such as URL= links in the rendered SVG).

Introduce internal/dotwriter, a small structured DOT digraph writer that encapsulates the underlying io.Writer and formats all identifiers and attribute lists through a single serializer:

  • Plain string attribute values and graph/legend titles are always DOT-escaped and quoted.
  • Multi-line labels with intentional \n or \l breaks are represented by an opaque dotwriter.Text type that can only be constructed through escaping helpers (Escaped, LinesCenter, LinesLeft, Join, JoinLinesCenter).
  • Identifiers (dotwriter.ID) are emitted bare only when matching [A-Za-z_][A-Za-z0-9_]* and quoted/escaped otherwise.

Update internal/graph to emit all DOT output exclusively through dotwriter.Writer instead of embedding io.Writer, store plain newlines in joinLabels rather than pre-baked DOT \n sequences, and document and escape DotNodeAttributes.Formatter output line-by-line.

Fixes #769
Fixes #1020

Previously, ComposeDot built DOT statements via ad-hoc fmt.Sprintf and
fmt.Fprintf calls into an embedded io.Writer, relying on each call site
to remember escapeForDot. Several profile- or caller-supplied strings
were interpolated without escaping, including sample label and numeric
tag names in nodelets, FormatValue output (which incorporates custom
SampleType.Unit strings), LegendURL, and DotNodeAttributes.URL/Shape,
allowing double quotes in profile data to break out of quoted DOT
strings and inject arbitrary DOT attributes (such as URL= links in the
rendered SVG).

Introduce internal/dotwriter, a small structured DOT digraph writer that
encapsulates the underlying io.Writer and formats all identifiers and
attribute lists through a single serializer:
- Plain string attribute values and graph/legend titles are always
  DOT-escaped and quoted.
- Multi-line labels with intentional \n or \l breaks are represented by
  an opaque dotwriter.Text type that can only be constructed through
  escaping helpers (Escaped, LinesCenter, LinesLeft, Join,
  JoinLinesCenter).
- Identifiers (dotwriter.ID) are emitted bare only when matching
  [A-Za-z_][A-Za-z0-9_]* and quoted/escaped otherwise.

Update internal/graph to emit all DOT output exclusively through
dotwriter.Writer instead of embedding io.Writer, store plain newlines in
joinLabels rather than pre-baked DOT \n sequences, and document and
escape DotNodeAttributes.Formatter output line-by-line.

Fixes google#769
Fixes google#1020
@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.69%. Comparing base (4bf881d) to head (a6dd072).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1065      +/-   ##
==========================================
+ Coverage   73.55%   73.69%   +0.14%     
==========================================
  Files          46       47       +1     
  Lines        7957     8076     +119     
==========================================
+ Hits         5853     5952      +99     
- Misses       2082     2102      +20     
  Partials       22       22              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants