diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-19 09:54:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-19 09:54:32 +0000 |
commit | e585d5c85ba970bebd884ebaec35d23cea0581fb (patch) | |
tree | e4e65e9c3a02f8b6da4512b0f2d4fd93145d3f69 /lualib/lua_content | |
parent | 78ce6c313d9b8d1a104ba15d27363b5303cdc6c8 (diff) | |
download | rspamd-e585d5c85ba970bebd884ebaec35d23cea0581fb.tar.gz rspamd-e585d5c85ba970bebd884ebaec35d23cea0581fb.zip |
[Minor] Lua_content: Implement plain strings unescape
Diffstat (limited to 'lualib/lua_content')
-rw-r--r-- | lualib/lua_content/pdf.lua | 21 |
1 files 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 |