Skip to content

Commit

Permalink
Quote string attribute values
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Chlebek <[email protected]>
  • Loading branch information
echlebek committed Mar 14, 2019
1 parent c7a9451 commit dc921c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dot/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ func writeAttrs(w *bytes.Buffer, name string, tabs int, attrs map[string]interfa
sort.Sort(keys)
list := []string{}
for _, k := range keys {
list = append(list, fmt.Sprintf("%s=%v", k, attrs[k]))
v := attrs[k]
switch value := v.(type) {
case string:
list = append(list, fmt.Sprintf("%s=%q", k, value))
default:
list = append(list, fmt.Sprintf("%s=%v", k, value))
}
}
fmt.Fprintln(w, strings.Join(list, ", "), "];")
}
Expand Down
6 changes: 3 additions & 3 deletions dot/dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func TestDirectedDotWriter(t *testing.T) {

expected := `digraph {
graph [ splines=false ];
0 [ label=Happy ];
1 [ label=Sleepy, shape=egg ];
0 [ label="Happy" ];
1 [ label="Sleepy", shape="egg" ];
1 -> 0;
1 -> 2;
3 -> 1;
4 -> 3;
4 -> 5;
5 -> 6 [ arrowhead=diamond ];
5 -> 6 [ arrowhead="diamond" ];
6 -> 7;
6 -> 9;
9 -> 8;
Expand Down

0 comments on commit dc921c2

Please sign in to comment.