From b4bde5d7d38a4c35005d161ce72045d205939cf3 Mon Sep 17 00:00:00 2001 From: Ivo Danihelka Date: Fri, 6 Feb 2015 12:15:27 +0000 Subject: Escaped quotes for dot. --- init.lua | 5 +++-- test_graphviz.lua | 2 ++ 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 -- cgit v1.2.3