Skip to content

internal/graph: escape double quotes in tag names in DOT output#1008

Open
LeSingh1 wants to merge 1 commit into
google:mainfrom
LeSingh1:fix/escape-tag-names-in-dot
Open

internal/graph: escape double quotes in tag names in DOT output#1008
LeSingh1 wants to merge 1 commit into
google:mainfrom
LeSingh1:fix/escape-tag-names-in-dot

Conversation

@LeSingh1

Copy link
Copy Markdown

Fixes #769

Problem

Tag (nodelet) labels in the DOT renderer interpolate the tag name directly into the label = "..." attribute without escaping:

nodelets += fmt.Sprintf(`N%d_%d [label = "%s" ...]`, nodeID, i, t.Name, ...)

Every other label in dotgraph.go (node names, edge labels, legend title) is passed through escapeForDot, but the two tag-nodelet paths were not. A tag name containing a double quote — common in CPU-profile string tags, e.g. range_str:.../"{...}" — produces invalid DOT that graphviz cannot render, breaking the whole graph (see the example in #769).

Fix

Apply the existing escapeForDot helper to t.Name in both the label-tag path (tagsToNodelets) and the numeric-nodelet path (numericNodelets). No other behavior changes.

Test

Added TestComposeWithTagsThatNeedEscaping (golden compose10.dot): a label tag whose name contains " now renders as label = "range_str:\"{quote}\"". The test fails before this change (unescaped quote → malformed DOT) and passes after. Full internal/graph package tests pass; go vet and gofmt are clean.

Tag (nodelet) labels interpolated t.Name directly into the DOT
label="..." attribute without escaping, unlike node and edge labels
which use escapeForDot. A tag name containing a double quote (common in
CPU profile string tags) produced invalid DOT that graphviz could not
render. Apply escapeForDot to tag names in both the label-tag and
numeric-nodelet paths.

Fixes google#769
@aalexand

Copy link
Copy Markdown
Collaborator

It doesn't look like the proto "officially" disallows double-quote characters in the label/tag names, but it's pretty odd to have them there. What is the use case for this?

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.

quotes in CPU profile tags not escaped properly

2 participants