From e6b5fe590f70c0bf563a5d6e2b1ac867dc8525ed Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 19 Jan 2016 16:30:00 -0800 Subject: [PATCH] fix a certain case in serialize.lua this should actually check if the whole string matches [A-Za-z_][0-9A-Za-z_]* but thats for another time --- Lua/lib/serialize.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Lua/lib/serialize.lua b/Lua/lib/serialize.lua index 0d7b721..1cf3494 100644 --- a/Lua/lib/serialize.lua +++ b/Lua/lib/serialize.lua @@ -16,7 +16,9 @@ local function kill_bom(s) end local function sanitize(v) - return type(v) == 'string' and strfmt('%q', v) or tostring(v) + local force = type(v) == 'string' and v:sub(1, 1):match('%d') + force = force and true or false + return type(v) == 'string' and strfmt('%q', v) or tostring(v), force end local function _serialize(value, writer, level) @@ -25,15 +27,16 @@ local function _serialize(value, writer, level) local indent = strrep('\t', level) writer('{\n') for key,value in opairs(value) do - local sane = sanitize(key) - local keyval = sane == '"'..key..'"' and key or '['..sane..']' + local sane, force = sanitize(key) + local keyval = (sane == '"'..key..'"' and not force) and key or '['..sane..']' writer(indent..keyval..' = ') _serialize(value, writer, level + 1) writer(',\n') end writer(strrep('\t', level - 1)..'}') else - writer(sanitize(value)) + local sane, force = sanitize(value) + writer(sane) end end