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 11'use strict' ;
22
3- var regex = / ^ (?: \r \n | \n | \r ) + | (?: \r \n | \n | \r ) + $ / g;
3+ var regex = / ^ (?: \r | \n ) + | (?: \r | \n ) + $ / g;
44
55module . exports = function ( str ) {
66 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 () {
1919 assert . strictEqual ( trimOffNewlines ( '\r\nunicorns\r\n' ) , 'unicorns' ) ;
2020 assert . strictEqual ( trimOffNewlines ( 'unicorns\r\n\r\n\r\n\r\n\r\n\r\n' ) , 'unicorns' ) ;
2121} ) ;
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