summaryrefslogtreecommitdiff
path: root/xmake/core/base/xml.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-15 20:02:25 +0800
committerruki <[email protected]>2025-11-15 20:02:25 +0800
commit88b0fb7c39cd6b867cdde29fd195f5f2c49b62d7 (patch)
tree6c94b4d7f5f34e3aed92923c66db52c68ac74ac1 /xmake/core/base/xml.lua
parent9c8f2febdddbe6e1ca4f6e04d4ba0d6f4f0f364f (diff)
improve to parse attrs
Diffstat (limited to 'xmake/core/base/xml.lua')
-rw-r--r--xmake/core/base/xml.lua30
1 files changed, 28 insertions, 2 deletions
diff --git a/xmake/core/base/xml.lua b/xmake/core/base/xml.lua
index beb3a2ed4..7dc0025b8 100644
--- a/xmake/core/base/xml.lua
+++ b/xmake/core/base/xml.lua
@@ -84,10 +84,36 @@ end
-- parse attribute string to table (or nil if empty)
function xml._parse_attrs(attrstr)
local attrs
- attrstr:gsub("([%w_:%-%.]+)%s*=%s*([\"'])(.-)%2", function(key, quote, value)
+ local i, len = 1, #attrstr
+ while i <= len do
+ local key, value_start = attrstr:match("^%s*([%w_:%-%.]+)%s*=%s*()", i)
+ if not key then
+ break
+ end
+ local value
+ local first_char = attrstr:sub(value_start, value_start)
+ if first_char == "\"" or first_char == "'" then
+ local closing = attrstr:find(first_char, value_start + 1, true)
+ if not closing then
+ break
+ end
+ value = attrstr:sub(value_start + 1, closing - 1)
+ i = closing + 1
+ else
+ local j = value_start
+ while j <= len do
+ local ch = attrstr:sub(j, j)
+ if ch:match("%s") or ch == ">" or (ch == "/" and attrstr:sub(j + 1, j + 1) == ">") then
+ break
+ end
+ j = j + 1
+ end
+ value = attrstr:sub(value_start, j - 1)
+ i = j
+ end
attrs = attrs or {}
attrs[key] = xml._decode_entities(value)
- end)
+ end
return attrs
end