Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/graph.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoray kavukcuoglu <koray@kavukcuoglu.org>2015-02-07 04:48:03 +0300
committerkoray kavukcuoglu <koray@kavukcuoglu.org>2015-02-07 04:48:03 +0300
commitfbf41c34f41ce4487fa732b8d5ec19d37fefcac1 (patch)
tree02b40959f11711c54c0d83274dce274c65b836f2
parent76e09cdb159706d54e23862a3e949e3e78712889 (diff)
parentb4bde5d7d38a4c35005d161ce72045d205939cf3 (diff)
Merge pull request #10 from fidlej/topic_escape_quotes
Escaped quotes for dot.
-rw-r--r--init.lua5
-rw-r--r--test_graphviz.lua2
2 files changed, 5 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 8c588bf..4437df6 100644
--- a/init.lua
+++ b/init.lua
@@ -167,8 +167,9 @@ end
function graph._dotEscape(str)
if string.find(str, '[^a-zA-Z]') then
- -- Escape newlines.
+ -- Escape newlines and quotes.
local escaped = string.gsub(str, '\n', '\\n')
+ escaped = string.gsub(escaped, '"', '\\"')
str = '"' .. escaped .. '"'
end
return str
@@ -180,7 +181,7 @@ end
strings properly.
]]
local function makeAttributeString(attributes)
- str = {}
+ local str = {}
for k, v in pairs(attributes) do
table.insert(str, tostring(k) .. '=' .. graph._dotEscape(tostring(v)))
end
diff --git a/test_graphviz.lua b/test_graphviz.lua
index 3a18cba..f0f15b2 100644
--- a/test_graphviz.lua
+++ b/test_graphviz.lua
@@ -30,6 +30,8 @@ function tests.testDotEscape()
'Use quotes for non-alpha characters')
tester:assert(graph._dotEscape('My\nnewline') == '"My\\nnewline"',
'Escape newlines')
+ tester:assert(graph._dotEscape('Say "hello"') == '"Say \\"hello\\""',
+ 'Escape quotes')
end