commit e585d5c: [Minor] Lua_content: Implement plain strings unescape
Vsevolod Stakhov
vsevolod at highsecure.ru
Sun Jan 19 09:56:07 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-01-19 09:54:32 +0000
URL: https://github.com/rspamd/rspamd/commit/e585d5c85ba970bebd884ebaec35d23cea0581fb (HEAD -> master)
[Minor] Lua_content: Implement plain strings unescape
---
lualib/lua_content/pdf.lua | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lualib/lua_content/pdf.lua b/lualib/lua_content/pdf.lua
index b577677e8..f1f9badda 100644
--- a/lualib/lua_content/pdf.lua
+++ b/lualib/lua_content/pdf.lua
@@ -201,7 +201,24 @@ local function generic_grammar_elts()
end
local function pdf_string_unescape(s)
- -- TODO: add unescaping logic
+ local function ue_single(cc)
+ if cc == '\\r' then
+ return '\r'
+ elseif cc == '\\n' then
+ return '\n'
+ else
+ return cc:gsub(2, 2)
+ end
+ end
+ -- simple unescape \char
+ s = s:gsub('\\[^%d]', ue_single)
+ -- unescape octal
+ local function ue_octal(cc)
+ -- Replace unknown stuff with '?'
+ return string.char(tonumber(cc:sub(2), 8) or 63)
+ end
+ s = s:gsub('\\%d%d?%d?', ue_octal)
+
return s
end
@@ -226,7 +243,7 @@ local function generic_grammar_elts()
grammar_elts.number = C(sign * (float + decimal)) / tonumber
-- String
- grammar_elts.str = P{ "(" * C(((1 - S"()") + V(1))^0) / pdf_string_unescape * ")" }
+ grammar_elts.str = P{ "(" * C(((1 - S"()\\") + (P '\\' * 1) + V(1))^0) / pdf_string_unescape * ")" }
grammar_elts.hexstr = P{"<" * C(hex^0) / pdf_hexstring_unescape * ">"}
-- Identifier
More information about the Commits
mailing list