diff options
author | koray kavukcuoglu <koray@kavukcuoglu.org> | 2015-02-07 04:48:03 +0300 |
---|---|---|
committer | koray kavukcuoglu <koray@kavukcuoglu.org> | 2015-02-07 04:48:03 +0300 |
commit | fbf41c34f41ce4487fa732b8d5ec19d37fefcac1 (patch) | |
tree | 02b40959f11711c54c0d83274dce274c65b836f2 | |
parent | 76e09cdb159706d54e23862a3e949e3e78712889 (diff) | |
parent | b4bde5d7d38a4c35005d161ce72045d205939cf3 (diff) |
Merge pull request #10 from fidlej/topic_escape_quotes
Escaped quotes for dot.
-rw-r--r-- | init.lua | 5 | ||||
-rw-r--r-- | test_graphviz.lua | 2 |
2 files changed, 5 insertions, 2 deletions
@@ -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 |