From 84513e118e5f1ab71fe9b377924cb355590649f2 Mon Sep 17 00:00:00 2001 From: Henning Bopp Date: Sat, 3 Nov 2018 15:09:35 +0100 Subject: [PATCH 1/2] Allow Backslash Escaping of Pipes Allows output with pipe `|` in it if it is properly escaped (`\|`) --- argos@pew.worldwidemann.com/utilities.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/argos@pew.worldwidemann.com/utilities.js b/argos@pew.worldwidemann.com/utilities.js index 5cb795f..5adf60a 100644 --- a/argos@pew.worldwidemann.com/utilities.js +++ b/argos@pew.worldwidemann.com/utilities.js @@ -74,6 +74,10 @@ function parseLine(lineString) { let separatorIndex = lineString.indexOf("|"); + while(lineString.substr(separatorIndex-1,1) == '\\'){ + separatorIndex = lineString.indexOf("|", separatorIndex+1); + } + if (separatorIndex >= 0) { let attributes = []; try { From b33183f259a318739811a1194d540ceb33d695fd Mon Sep 17 00:00:00 2001 From: Henning Bopp Date: Sat, 17 Nov 2018 20:43:34 +0100 Subject: [PATCH 2/2] Optimized matching/splitting for escaped Pipes Exchanged character matching with Regexp using negative lookbehind --- argos@pew.worldwidemann.com/utilities.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/argos@pew.worldwidemann.com/utilities.js b/argos@pew.worldwidemann.com/utilities.js index 5adf60a..c685a62 100644 --- a/argos@pew.worldwidemann.com/utilities.js +++ b/argos@pew.worldwidemann.com/utilities.js @@ -72,16 +72,13 @@ function parseFilename(filename) { function parseLine(lineString) { let line = {}; - let separatorIndex = lineString.indexOf("|"); + let separatedLine = GLib.regex_split_simple("(?= 0) { + if (separatedLine.length > 0) { let attributes = []; try { - attributes = GLib.shell_parse_argv(lineString.substring(separatorIndex + 1))[1]; + attributes = GLib.shell_parse_argv(separatedLine.join('|'))[1]; } catch (error) { log("Unable to parse attributes for line '" + lineString + "': " + error); } @@ -97,12 +94,6 @@ function parseLine(lineString) { line[name] = value; } } - - line.text = lineString.substring(0, separatorIndex); - - } else { - // Line has no attributes - line.text = lineString; } let leadingDashes = line.text.search(/[^-]/);