From: Vsevolod Stakhov Date: Mon, 27 Mar 2017 09:01:56 +0000 (+0100) Subject: [Fix] Fix templates grammar usage X-Git-Tag: 1.5.4~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7522631b4a5d98a7a38429716f0e56286c7d3c2c;p=rspamd.git [Fix] Fix templates grammar usage --- diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index c224c241a..e20089967 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -40,17 +40,14 @@ local E = {} local N = 'dkim_signing' local redis_params -local template_grammar local function simple_template(tmpl, keys) local lpeg = require "lpeg" - if not template_grammar then - local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } - local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } - local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } + local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } + local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } + local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } - template_grammar = lpeg.Cs((var + var_braced + 1)^0) - end + local template_grammar = lpeg.Cs((var + var_braced + 1)^0) return lpeg.match(template_grammar, tmpl) end diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua index 8d0778ad5..3c0e1b2dc 100644 --- a/src/plugins/lua/metadata_exporter.lua +++ b/src/plugins/lua/metadata_exporter.lua @@ -128,17 +128,14 @@ local function get_general_metadata(task, flatten, no_content) return r end -local template_grammar local function simple_template(tmpl, keys) local lpeg = require "lpeg" - if not template_grammar then - local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } - local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } - local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } + local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } + local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } + local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } - template_grammar = lpeg.Cs((var + var_braced + 1)^0) - end + local template_grammar = lpeg.Cs((var + var_braced + 1)^0) return lpeg.match(template_grammar, tmpl) end