From 637dfbf90aa681358e7b6fe1f0cba6e74e055ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Tue, 19 Dec 2023 23:27:31 +0100 Subject: [PATCH] Escaping control characters --- luamml-xmlwriter.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/luamml-xmlwriter.lua b/luamml-xmlwriter.lua index cbdc1f1..47d4385 100644 --- a/luamml-xmlwriter.lua +++ b/luamml-xmlwriter.lua @@ -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("", escape_text"") local attrs = {} local function write_elem(tree, indent)