mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-13 14:34:33 +00:00
Perform list substitution only on word boundaries
When performing list substitution, only replace a list name when it is surrounded by whitespace or expected punctuation characters. Lua patterns don't have a notion of this-or-that patterns e.g. (^|abc), so we have 3 versions of the substitution depending on whether he list name occurs in the beginning, middle, or end of a string. This fixes #197.
This commit is contained in:
parent
42e50356cf
commit
f1b44da90c
@ -325,7 +325,12 @@ end
|
||||
function compiler.compile_filter(name, source, macro_defs, list_defs)
|
||||
|
||||
for name, items in pairs(list_defs) do
|
||||
source = string.gsub(source, name, table.concat(items, ", "))
|
||||
local begin_name_pat = "^("..name..")([%s(),=])"
|
||||
local mid_name_pat = "([%s(),=])("..name..")([%s(),=])"
|
||||
local end_name_pat = "([%s(),=])("..name..")$"
|
||||
source = string.gsub(source, begin_name_pat, table.concat(items, ", ").."%2")
|
||||
source = string.gsub(source, mid_name_pat, "%1"..table.concat(items, ", ").."%3")
|
||||
source = string.gsub(source, end_name_pat, "%1"..table.concat(items, ", "))
|
||||
end
|
||||
|
||||
local ast, error_msg = parser.parse_filter(source)
|
||||
|
Loading…
Reference in New Issue
Block a user