Skip to content

Commit

Permalink
fix: cve 2023-26115
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafConijn committed Jul 13, 2023
1 parent d6e8514 commit 9f62693
Show file tree
Hide file tree
Showing 2 changed files with 3,092 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
* Released under the MIT License.
*/

function trimEnd(str) {
let lastCharPos = str.length - 1;
let lastChar = str[lastCharPos];
while(lastChar === ' ' || lastChar === '\t') {
lastChar = str[--lastCharPos];
}
return str.substring(0, lastCharPos + 1);
}

function trimTabAndSpaces(str) {
const lines = str.split('\n');
const trimmedLines = lines.map((line) => trimEnd(line));
return trimmedLines.join('\n');
}

module.exports = function(str, options) {
options = options || {};
if (str == null) {
Expand Down Expand Up @@ -36,7 +51,7 @@ module.exports = function(str, options) {
}).join(newline);

if (options.trim === true) {
result = result.replace(/\s+$/g, '');
result = trimTabAndSpaces(result);
}
return result;
};
Expand Down
Loading

0 comments on commit 9f62693

Please sign in to comment.