From b04e208bc3feee94558e86f5c0f48caf480a1ef6 Mon Sep 17 00:00:00 2001 From: "elias.oelschner" Date: Wed, 18 Feb 2026 14:22:07 +0100 Subject: [PATCH] Fix string escaping for printable ASCII --- src/prometheus/util.lua | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/prometheus/util.lua b/src/prometheus/util.lua index 1c64bf4..8d33421 100644 --- a/src/prometheus/util.lua +++ b/src/prometheus/util.lua @@ -26,8 +26,9 @@ end local function escape(str) return str:gsub(".", function(char) - if char:match("[^ %-~\n\t\a\b\v\r\"\']") then -- Check if non Printable ASCII Character - return string.format("\\%03d", string.byte(char)) + local byte = string.byte(char) + if byte >= 32 and byte <= 126 and char ~= "\\" and char ~= "\"" and char ~= "\'" then + return char end if(char == "\\") then return "\\\\"; @@ -38,25 +39,13 @@ local function escape(str) if(char == "\r") then return "\\r"; end - if(char == "\t") then - return "\\t"; - end - if(char == "\a") then - return "\\a"; - end - if(char == "\b") then - return "\\b"; - end - if(char == "\v") then - return "\\v"; - end if(char == "\"") then return "\\\""; end if(char == "\'") then return "\\\'"; end - return char; + return string.format("\\%03d", byte); end) end