Skip to content

Commit

Permalink
Merge pull request #3 from Trott/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao authored Sep 17, 2021
2 parents 3a728c9 + 6d89476 commit fcbb73d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var regex = /^(?:\r\n|\n|\r)+|(?:\r\n|\n|\r)+$/g;
var regex = /^(?:\r|\n)+|(?:\r|\n)+$/g;

module.exports = function (str) {
return str.replace(regex, '');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
"remove",
"delete"
],
"dependencies": {},
"devDependencies": {
"mocha": "*",
"xo": "*"
"xo": "^0.17.1"
},
"xo": {
"envs": [
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ it('should trim off \\r\\n', function () {
assert.strictEqual(trimOffNewlines('\r\nunicorns\r\n'), 'unicorns');
assert.strictEqual(trimOffNewlines('unicorns\r\n\r\n\r\n\r\n\r\n\r\n'), 'unicorns');
});

it('should not be susceptible to exponential backtracking', function () {
var start = Date.now();
trimOffNewlines('a' + '\r\n'.repeat(1000) + 'a');
var end = Date.now();
assert.ok(end - start < 1000, 'took too long, probably susceptible to ReDOS');
});

0 comments on commit fcbb73d

Please sign in to comment.