1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-05-17 21:23:22 -07:00

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
This commit is contained in:
Connor Olding 2016-01-19 16:30:00 -08:00
parent 617a10cba3
commit e6b5fe590f

View File

@ -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