Skip to content

Commit b04e208

Browse files
committed
Fix string escaping for printable ASCII
1 parent 742a692 commit b04e208

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/prometheus/util.lua

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ end
2626

2727
local function escape(str)
2828
return str:gsub(".", function(char)
29-
if char:match("[^ %-~\n\t\a\b\v\r\"\']") then -- Check if non Printable ASCII Character
30-
return string.format("\\%03d", string.byte(char))
29+
local byte = string.byte(char)
30+
if byte >= 32 and byte <= 126 and char ~= "\\" and char ~= "\"" and char ~= "\'" then
31+
return char
3132
end
3233
if(char == "\\") then
3334
return "\\\\";
@@ -38,25 +39,13 @@ local function escape(str)
3839
if(char == "\r") then
3940
return "\\r";
4041
end
41-
if(char == "\t") then
42-
return "\\t";
43-
end
44-
if(char == "\a") then
45-
return "\\a";
46-
end
47-
if(char == "\b") then
48-
return "\\b";
49-
end
50-
if(char == "\v") then
51-
return "\\v";
52-
end
5342
if(char == "\"") then
5443
return "\\\"";
5544
end
5645
if(char == "\'") then
5746
return "\\\'";
5847
end
59-
return char;
48+
return string.format("\\%03d", byte);
6049
end)
6150
end
6251

0 commit comments

Comments
 (0)