Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draw.DOT escaping #95

Open
Zincr0 opened this issue Apr 10, 2023 · 2 comments
Open

draw.DOT escaping #95

Zincr0 opened this issue Apr 10, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Zincr0
Copy link

Zincr0 commented Apr 10, 2023

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

@dominikbraun dominikbraun added the bug Something isn't working label Apr 10, 2023
@Zincr0
Copy link
Author

Zincr0 commented Apr 12, 2023

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

@dominikbraun
Copy link
Owner

dominikbraun commented Apr 12, 2023

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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants