From ebed9f8dfd8fbeff2b6f81008ad4bc26f1001480 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Wed, 9 Aug 2017 17:53:53 -0700 Subject: [PATCH] Remove trailing newlines from output If in yaml, the output field is folded-style aka: output: < some multi-line output here The unfolded string will have a trailing newline. Remove it. --- userspace/engine/lua/compiler.lua | 1 + userspace/engine/lua/parser.lua | 1 + userspace/engine/lua/rule_loader.lua | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/userspace/engine/lua/compiler.lua b/userspace/engine/lua/compiler.lua index 6fadb8d1761..0feed84e5d2 100644 --- a/userspace/engine/lua/compiler.lua +++ b/userspace/engine/lua/compiler.lua @@ -20,6 +20,7 @@ local compiler = {} compiler.verbose = false compiler.all_events = false +compiler.trim = parser.trim function compiler.set_verbose(verbose) compiler.verbose = verbose diff --git a/userspace/engine/lua/parser.lua b/userspace/engine/lua/parser.lua index 7fb5a317cbd..b240635d837 100644 --- a/userspace/engine/lua/parser.lua +++ b/userspace/engine/lua/parser.lua @@ -127,6 +127,7 @@ function trim(s) if (type(s) ~= "string") then return s end return (s:gsub("^%s*(.-)%s*$", "%1")) end +parser.trim = trim local function terminal (tag) -- Rather than trim the whitespace in this way, it would be nicer to exclude it from the capture... diff --git a/userspace/engine/lua/rule_loader.lua b/userspace/engine/lua/rule_loader.lua index 0f4d828eca8..335474e93e3 100644 --- a/userspace/engine/lua/rule_loader.lua +++ b/userspace/engine/lua/rule_loader.lua @@ -243,6 +243,10 @@ function load_rules(rules_content, rules_mgr, verbose, all_events, extra, replac state.ordered_rule_names[#state.ordered_rule_names+1] = v['rule'] end + -- The output field might be a folded-style, which adds a + -- newline to the end. Remove any trailing newlines. + v['output'] = compiler.trim(v['output']) + state.rules_by_name[v['rule']] = v else