Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/graph/dotgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (b *builder) start() {
if b.config.Title != "" {
graphname = b.config.Title
}
fmt.Fprintln(b, `digraph "`+graphname+`" {`)
fmt.Fprintln(b, `digraph "`+escapeForDot(graphname)+`" {`)
fmt.Fprintln(b, `node [style=filled fillcolor="#f8f8f8"]`)
}

Expand All @@ -132,7 +132,7 @@ func (b *builder) addLegend() {
fmt.Fprintf(b, ` URL="%s" target="_blank"`, b.config.LegendURL)
}
if b.config.Title != "" {
fmt.Fprintf(b, ` tooltip="%s"`, b.config.Title)
fmt.Fprintf(b, ` tooltip="%s"`, escapeForDot(b.config.Title))
}
fmt.Fprintf(b, "] }\n")
}
Expand Down Expand Up @@ -390,7 +390,10 @@ func multilinePrintableName(info *NodeInfo) string {
infoCopy.Name = strings.ReplaceAll(infoCopy.Name, "[...]", "[…]")
infoCopy.Name = strings.ReplaceAll(infoCopy.Name, ".", `\n`)
if infoCopy.File != "" {
infoCopy.File = filepath.Base(infoCopy.File)
infoCopy.File = escapeForDot(filepath.Base(infoCopy.File))
}
if infoCopy.Objfile != "" {
infoCopy.Objfile = escapeForDot(filepath.Base(infoCopy.Objfile))
}
return strings.Join(infoCopy.NameComponents(), `\n`) + `\n`
}
Expand Down
24 changes: 20 additions & 4 deletions internal/graph/dotgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,29 @@ func TestComposeWithStandardGraphAndURL(t *testing.T) {
func TestComposeWithNamesThatNeedEscaping(t *testing.T) {
g := baseGraph()
a, c := baseAttrsAndConfig()
g.Nodes[0].Info = NodeInfo{Name: `var"src"`}
g.Nodes[1].Info = NodeInfo{Name: `var"#dest#"`}
g.Nodes[0].Info = NodeInfo{Name: `var"src"`, File: `/src/file"name.go`, Lineno: 10}
g.Nodes[1].Info = NodeInfo{Address: 0x10, Objfile: `/lib/obj"file.so`}
c.Title = `test"title`
c.Labels = []string{"legend", `label"text`}

var buf bytes.Buffer
ComposeDot(&buf, g, a, c)

compareGraphs(t, buf.Bytes(), "compose7.dot")
got := buf.String()

for _, tc := range []struct{ raw, escaped string }{
{`var"src"`, `var\"src\"`},
{`file"name.go`, `file\"name.go`},
{`obj"file.so`, `obj\"file.so`},
{`test"title`, `test\"title`},
{`label"text`, `label\"text`},
} {
if strings.Contains(got, tc.raw) {
t.Errorf("unescaped %q in dot output:\n%s", tc.raw, got)
}
if !strings.Contains(got, tc.escaped) {
t.Errorf("escaped %q not found in dot output:\n%s", tc.escaped, got)
}
}
}

func TestComposeWithCommentsWithNewlines(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions internal/graph/testdata/compose7.dot

This file was deleted.

Loading