From 235cfd4fe3dbd546d1f2b52b70aa717614b7e4d6 Mon Sep 17 00:00:00 2001 From: Aashutosh Rathi Date: Sat, 25 Mar 2023 11:31:54 +0530 Subject: [PATCH 1/2] :lock: fix: CVE-2023-26115 --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 680ec5d..461a17c 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,16 @@ /*! * word-wrap * - * Copyright (c) 2014-2017, Jon Schlinkert. + * Copyright (c) 2014-2023, Jon Schlinkert. * Released under the MIT License. */ +function trimTabAndSpaces(str) { + const lines = str.split('\n'); + const trimmedLines = lines.map((line) => line.trimEnd()); + return trimmedLines.join('\n'); +} + module.exports = function(str, options) { options = options || {}; if (str == null) { @@ -36,7 +42,7 @@ module.exports = function(str, options) { }).join(newline); if (options.trim === true) { - result = result.replace(/[ \t]*$/gm, ''); + result = trimTabAndSpaces(result); } return result; }; From d6e85142e85d939faeaac4307dcb19f15e553027 Mon Sep 17 00:00:00 2001 From: Aashutosh Rathi Date: Fri, 9 Jun 2023 18:55:21 +0000 Subject: [PATCH 2/2] fix: settle for new regex to support lower node versions --- index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/index.js b/index.js index 461a17c..a79aef7 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,6 @@ * Released under the MIT License. */ -function trimTabAndSpaces(str) { - const lines = str.split('\n'); - const trimmedLines = lines.map((line) => line.trimEnd()); - return trimmedLines.join('\n'); -} - module.exports = function(str, options) { options = options || {}; if (str == null) { @@ -42,7 +36,7 @@ module.exports = function(str, options) { }).join(newline); if (options.trim === true) { - result = trimTabAndSpaces(result); + result = result.replace(/\s+$/g, ''); } return result; };