From 801b640dc67fe6bf003e50af3ff7d262140cf1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Stenstr=C3=B6m?= Date: Wed, 14 May 2025 17:51:18 +0300 Subject: [PATCH 1/3] Testcommit to check everything is correctly setup. --- .gitignore | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 156ecc0..f648248 100755 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,15 @@ *.rock -test.lua -teste.lua #IntelliJ IDEA Files .idea *.iml +#VS Code files +launch.json + #macOS .DS_Store + +#Debugging files +debugger.lua +test.lua From dcba5c715c3e635df1a93cbb6420c7c4ac12f33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Stenstr=C3=B6m?= Date: Wed, 14 May 2025 20:16:57 +0300 Subject: [PATCH 2/3] Fixed tags with args and vals --- xml2lua.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xml2lua.lua b/xml2lua.lua index 813cf1e..b7c6c5b 100755 --- a/xml2lua.lua +++ b/xml2lua.lua @@ -237,7 +237,7 @@ end function xml2lua.parseTableToXml(obj, tagName, level) if (tagName ~= '_attr') then - if (type(obj) == 'table') then + if (type(obj) == 'table' and (#obj ~= 1 or type(obj[1]) == 'table')) then if (xml2lua.isChildArray(obj)) then for _, value in pairs(obj) do xml2lua.parseTableToXml(value, tagName, level) @@ -252,10 +252,14 @@ function xml2lua.parseTableToXml(obj, tagName, level) xml2lua.endTag(tagName, level) end else - xml2lua.addTagValueAttr(tagName, obj, nil, level) + if type(obj) == 'table' then + xml2lua.addTagValueAttr(tagName, obj[1], obj._attr, level) + else + xml2lua.addTagValueAttr(tagName, obj, nil, level) + end end end - end +end ---Converts a Lua table to a XML String representation. --@param tb Table to be converted to XML From 965f04669f90fc05a30d3989af56dd5089198d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Stenstr=C3=B6m?= Date: Mon, 27 Jul 2026 14:51:04 +0300 Subject: [PATCH 3/3] Added subtitution for disallowed characters --- xml2lua.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xml2lua.lua b/xml2lua.lua index b7c6c5b..71b98d0 100755 --- a/xml2lua.lua +++ b/xml2lua.lua @@ -140,6 +140,18 @@ function xml2lua.loadFile(xmlFilePath) error(e) end +---Checks the value for forbidden characters and escapes them +--@param value string for checking and correcting +--@return a XML-compliant string +local function escapeXmlChar(value) + value = string.gsub(value, "&", "&") + value = string.gsub(value, "<", "<") + value = string.gsub(value, ">", ">") + value = string.gsub(value, "'", "'") + value = string.gsub(value, "\"", """) + return value +end + ---Gets an _attr element from a table that represents the attributes of an XML tag, --and generates a XML String representing the attibutes to be inserted --into the openning tag of the XML @@ -151,7 +163,7 @@ local function attrToXml(attrTable) attrTable = attrTable or {} for k, v in pairs(attrTable) do - s = s .. " " .. k .. "=" .. '"' .. v .. '"' + s = s .. " " .. k .. "=" .. '"' .. escapeXmlChar(v) .. '"' end return s end @@ -198,7 +210,7 @@ function xml2lua.addTagValueAttr(tagName, tagValue, attrTable, level) if (tagValue == '') then table.insert(xml2lua.xmltb, spaces .. '<' .. tagName .. attrStr .. '/>') else - table.insert(xml2lua.xmltb, spaces .. '<' .. tagName .. attrStr .. '>' .. tostring(tagValue) .. '') + table.insert(xml2lua.xmltb, spaces .. '<' .. tagName .. attrStr .. '>' .. escapeXmlChar(tostring(tagValue)) .. '') end end