From 8ac330b08a7acbcfebacc5be260407acc186b6e9 Mon Sep 17 00:00:00 2001 From: sorleone Date: Thu, 25 Apr 2019 19:17:15 +0200 Subject: [PATCH 1/2] Added function to escape regular expression chars In the case of a binary filename containing characters that have a special meaning inside regular expressions, the installation/uninstallation fails. Source for the solution: https://stackoverflow.com/a/9310752 --- lib/installer.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 1e1e207..160e1ce 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -45,6 +45,16 @@ const scriptFromShell = (shell = systemShell()) => { return path.join(__dirname, 'scripts/bash.sh'); }; +/** + * Helper to escape regular expression chars + * + * @param {String} str - String to escape the chars from + * @returns The escaped text + */ +const escapeRegExp = (str) => { + return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); +} + /** * Helper to return the expected location for SHELL config file, based on the * provided shell value. @@ -122,7 +132,7 @@ const checkFilenameForLine = async (filename, line) => { } } - return !!filecontent.match(`${line}`); + return !!filecontent.match(escapeRegExp(`${line}`)); }; /** @@ -324,7 +334,7 @@ const removeLinesFromFilename = async (filename, name) => { ? `# tabtab source for packages` : `# tabtab source for ${name} package`; - const hasLine = !!filecontent.match(`${sourceLine}`); + const hasLine = !!filecontent.match(escapeRegExp(`${sourceLine}`)); if (!hasLine) { return debug('File %s does not include the line: %s', filename, sourceLine); } From 121232295f780257cc41a6126f31f372e187e380 Mon Sep 17 00:00:00 2001 From: sorleone Date: Thu, 25 Apr 2019 20:44:35 +0200 Subject: [PATCH 2/2] Added missing function call --- lib/installer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/installer.js b/lib/installer.js index 160e1ce..88022e4 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -343,7 +343,7 @@ const removeLinesFromFilename = async (filename, name) => { const buffer = lines // Build up the new buffer, removing the 3 lines following the sourceline .map((line, index) => { - const match = line.match(sourceLine); + const match = line.match(escapeRegExp(sourceLine)); if (match) { lineIndex = index; } else if (lineIndex + 3 <= index) {