Skip to content

Commit 9f62693

Browse files
committed
fix: cve 2023-26115
1 parent d6e8514 commit 9f62693

File tree

2 files changed

+3092
-1
lines changed

2 files changed

+3092
-1
lines changed

index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
* Released under the MIT License.
66
*/
77

8+
function trimEnd(str) {
9+
let lastCharPos = str.length - 1;
10+
let lastChar = str[lastCharPos];
11+
while(lastChar === ' ' || lastChar === '\t') {
12+
lastChar = str[--lastCharPos];
13+
}
14+
return str.substring(0, lastCharPos + 1);
15+
}
16+
17+
function trimTabAndSpaces(str) {
18+
const lines = str.split('\n');
19+
const trimmedLines = lines.map((line) => trimEnd(line));
20+
return trimmedLines.join('\n');
21+
}
22+
823
module.exports = function(str, options) {
924
options = options || {};
1025
if (str == null) {
@@ -36,7 +51,7 @@ module.exports = function(str, options) {
3651
}).join(newline);
3752

3853
if (options.trim === true) {
39-
result = result.replace(/\s+$/g, '');
54+
result = trimTabAndSpaces(result);
4055
}
4156
return result;
4257
};

0 commit comments

Comments
 (0)