Skip to content

Commit

Permalink
Fix string escaping (#19)
Browse files Browse the repository at this point in the history
Properly escape strings containing quotes to prevent graphviz parsing errors
  • Loading branch information
Merovius authored and bradleyjkemp committed Jan 25, 2018
1 parent f9fe9a4 commit b236a53
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ func (m *mapper) mapPtrIface(iVal reflect.Value, inlineable bool) (nodeID, strin
}

func (m *mapper) mapString(stringVal reflect.Value, inlineable bool) (nodeID, string) {
quoted := fmt.Sprintf("\\\"%s\\\"", stringVal.String())
// We want the output to look like a Go quoted string literal. The first
// Quote achieves that. The second is to quote it for graphviz itself.
quoted := strconv.Quote(strconv.Quote(stringVal.String()))
// Lastly, quoting adds quotation-marks around the string, but it is
// inserted into a graphviz string literal, so we have to remove those.
quoted = quoted[1 : len(quoted)-1]
if inlineable {
return 0, quoted
}
Expand Down

0 comments on commit b236a53

Please sign in to comment.