From d866c96042f3e409a37c813a6129aa01b181499c Mon Sep 17 00:00:00 2001 From: David Date: Fri, 7 Aug 2026 18:36:39 +0000 Subject: [PATCH 1/2] flatten statment to return "" on self closed empty tags --- lib/comicxml.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/comicxml.lua b/lib/comicxml.lua index 6f478ec..a9f5581 100644 --- a/lib/comicxml.lua +++ b/lib/comicxml.lua @@ -99,12 +99,12 @@ function XmlObject:toTable(node) -- Add text if present and no children or attributes local text = node._text:match("^%s*(.-)%s*$") + if next(obj) == nil then + return text + end + if text ~= "" then - if next(obj) == nil then - return text - else - obj["text"] = text - end + obj["text"] = text end return obj From e72028fc5706aa2613e22bc5173d5c1400079970 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 7 Aug 2026 18:37:43 +0000 Subject: [PATCH 2/2] test case for empty self closed tags --- test/xml_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/xml_spec.lua b/test/xml_spec.lua index 0b9c3df..4f622ff 100644 --- a/test/xml_spec.lua +++ b/test/xml_spec.lua @@ -58,3 +58,26 @@ describe("xml object with array", function() end) end) end) + +describe("empty xml object with self closing tags", function() + describe("parse sample", function() + local xml = [[ + + + HelloWorld + + ]] + + local parser = XmlObject:new() + local root = parser:parse(xml) + local obj = parser:toTable(root) + + it(" should be null, no a table", function() + assert.equals("",obj.item) + assert.is_not.table(obj.item) + end) + it("item2 should exist and have value", function() + assert.equals( "HelloWorld", obj.item2) + end) + end) +end)