8000 draw.DOT escaping · Issue #95 · dominikbraun/graph · GitHub
[go: up one dir, main page]

Skip to content

draw.DOT escaping #95

Open
Open

Description

@Zincr0

Using draw.DOT over a network with valid golang string nodes, generates invalid .gv files if any string contain some special characters

example:

    g := graph.New(graph.StringHash, graph.Directed())

    _ = g.AddVertex("#cat:\"&(")
    _ = g.AddVertex("@dog")
    _ = g.AddVertex("\"big bird\"")

    _ = g.AddEdge("#cat:\"&(", "@dog")
    _ = g.AddEdge("#cat:\"&(", "\"big bird\"")

    file, _ := os.Create("./mygraph.gv")
    _ = draw.DOT(g, file)

Will generate

strict digraph {

	"#cat:"&(" [  weight=0 ];

	"#cat:"&(" -> ""big bird"" [  weight=0 ];

	"#cat:"&(" -> "@dog" [  weight=0 ];

	"@dog" [  weight=0 ];

	""big bird"" [  weight=0 ];

}

which will fail trying to use dot -Tsvg -O mygraph.gv since it has non escaped characters

dot -Tsvg -O mygraph.gv
Error: mygraph.gv: syntax error in line 3 near '&'

I think a flag to optionaly escape html entities may be a good alternative

Activity

  1. Zincr0 commented on Apr 12, 2023

    @Zincr0
    Author

    Note: strconv.Quote() seems to be doing the job quite well in my latest tests

  2. dominikbraun commented on Apr 12, 2023

    @dominikbraun
    Owner

    I've investigated the issue a bit. There are two separate challenges:

    1. Escaping HTML entities. This might be a new option for draw.DOT and is a feature on its own.
    2. Handling escaped double quotes (\") like in your example. The escaping backslash being removed is a bug, and it seems to happen when rendering the template: https://go.dev/play/p/DvuB5B8ywIV

    I'll focus on the \" bug for now. Maybe the escaping backslash can be preserved somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0