aysylu / loom

Graph library for Clojure. Mailing list https://groups.google.com/forum/#!forum/loom-clj
http://aysy.lu/loom/
887 stars 108 forks source link

loom.io: messed escaping in attributes #74

Open vtzi opened 8 years ago

vtzi commented 8 years ago

The problem happens when an attribute key or value is a collection and has items requiring escaping. Here is small snippet to reproduce it:

(gv/view (-> (gg/graph [1 2]) (ga/add-attr-to-edges :a ["AA.\"bb\""] [[1 2]])))

The problem is in dot-attrs function. str on collection escapes it: user> (str ["AA.\"bb\""]) "[\"AA.\"bb\"\"]"

I guess dot-attrs should be fully reworked somehow

danielcompton commented 8 years ago

@vtzi can you explain what output you were expecting?

(str ["AA.\"bb\""])
=> "[\"AA.\\\"bb\\\"\"]"
(println "[\"AA.\\\"bb\\\"\"]")
["AA.\"bb\""]
=> nil

This looks like normal Clojure escaping to me?

vtzi commented 8 years ago

@danielcompton the output of str is fine. the problem is that loom.io/dot-esc does not escape backslashes and graphviz gets really confused.

Escaping the backslash fixes the issue:

(defn- dot-esc [s](escape s {\ "\" " "\"" newline "\n"}))