We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0cd87f5 commit 6d89476Copy full SHA for 6d89476
2 files changed
index.js
@@ -1,6 +1,6 @@
1
'use strict';
2
3
-var regex = /^(?:\r\n|\n|\r)+|(?:\r\n|\n|\r)+$/g;
+var regex = /^(?:\r|\n)+|(?:\r|\n)+$/g;
4
5
module.exports = function (str) {
6
return str.replace(regex, '');
test.js
@@ -19,3 +19,10 @@ it('should trim off \\r\\n', function () {
19
assert.strictEqual(trimOffNewlines('\r\nunicorns\r\n'), 'unicorns');
20
assert.strictEqual(trimOffNewlines('unicorns\r\n\r\n\r\n\r\n\r\n\r\n'), 'unicorns');
21
});
22
+
23
+it('should not be susceptible to exponential backtracking', function () {
24
+ var start = Date.now();
25
+ trimOffNewlines('a' + '\r\n'.repeat(1000) + 'a');
26
+ var end = Date.now();
27
+ assert.ok(end - start < 1000, 'took too long, probably susceptible to ReDOS');
28
+});
0 commit comments