From a46e3d567963a4e287177e8f6a94ff8fed659906 Mon Sep 17 00:00:00 2001
From: onefang
Date: Mon, 23 Dec 2019 13:12:32 +1000
Subject: Attempt to sanitize the .lua table output.

Should get tested more, but it's good enough for now.
---
 apt-panopticommon.lua | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index 99dbeaf..42da301 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -250,7 +250,22 @@ dumpTableSub = function (table, space)
 	if type(v) == "table" then
 	    r = r .. APT.dumpTable(v, space, k)
 	elseif type(v) == "string" then
-	    r = r .. space .. "[" .. k .. "] = '" .. v .. "';\n"
+	    local bq = '"'
+	    local eq = '"'
+	    if nil ~= v:match(bq) then
+		bq, eq = '"', '"'
+		if nil ~= v:match(bq) then
+		    bq, eq = '[[', ']]'
+		    mbq, meq = '%[%[', '%]%]'
+		    while (nil ~= v:match(mbq)) or (nil ~= v:match(meq)) do
+			bq = '[' .. '=' .. bq:sub(2, -1)
+			eq = ']' .. '=' .. eq:sub(2, -1)
+			mbq = '%[' .. '=' .. bq:sub(3, -1)
+			meq = '%]' .. '=' .. eq:sub(3, -1)
+		    end
+		end
+	    end
+	    r = r .. space .. "[" .. k .. "] = " .. bq .. v .. eq .. ";\n"
 	elseif type(v) == "function" then
 	    r = r .. space .. "[" .. k .. "] = function ();\n"
 	elseif type(v) == "userdata" then
-- 
cgit v1.1