From f1b44da90c7b7f03bfba655f132dd3051021f653 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Fri, 30 Jun 2017 15:03:33 -0700 Subject: [PATCH] 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. --- userspace/engine/lua/compiler.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/userspace/engine/lua/compiler.lua b/userspace/engine/lua/compiler.lua index 405c5210..6fadb8d1 100644 --- a/userspace/engine/lua/compiler.lua +++ b/userspace/engine/lua/compiler.lua @@ -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)