Repository navigation
internal/graph: emit DOT via structured internal/dotwriter encoder - #1065
Merged
Merged
Conversation
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
aalexand
force-pushed
the
dot-attr-escaping
branch
from
November 10, 2026 00:37
fe53012 to
a6dd072
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
nolanmar511
approved these changes
Nov 10, 2026
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.
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:
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