File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- var regex = / ^ (?: \r \n | \n | \r ) + | (?: \r \n | \n | \r ) + $ / g;
3
+ var regex = / ^ (?: \r | \n ) + | (?: \r | \n ) + $ / g;
4
4
5
5
module . exports = function ( str ) {
6
6
return str . replace ( regex , '' ) ;
Original file line number Diff line number Diff line change @@ -19,3 +19,10 @@ it('should trim off \\r\\n', function () {
19
19
assert . strictEqual ( trimOffNewlines ( '\r\nunicorns\r\n' ) , 'unicorns' ) ;
20
20
assert . strictEqual ( trimOffNewlines ( 'unicorns\r\n\r\n\r\n\r\n\r\n\r\n' ) , 'unicorns' ) ;
21
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments