Escaping control characters

This commit is contained in:
Marcel Fabian Krüger 2023-12-19 23:27:31 +01:00
parent 89f8e2a79a
commit 637dfbf90a

View File

@ -10,8 +10,11 @@ local escapes = {
['&'] = "&",
}
local function escape_text(text)
return string.gsub(tostring(text), '["<>&]', escapes)
return string.gsub(string.gsub(tostring(text), '["<>&]', escapes), '[\x00-\x08\x0B\x0C\x0E-\x20]', function(x)
return string.format('^^%02x', string.byte(x))
end)
end
print("<node>", escape_text"<node>")
local attrs = {}
local function write_elem(tree, indent)