File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' markdown-to-jsx ' : patch
3
+ ---
4
+
5
+ Replace some regexes with optimized functions to avoid polynomial time scenarios. Also fixes compatibility issues in some older browsers with the ` trimEnd ` API.
Original file line number Diff line number Diff line change @@ -509,10 +509,10 @@ function generateListRule(
509
509
let adjustedContent
510
510
if ( thisItemIsAParagraph ) {
511
511
state . inline = false
512
- adjustedContent = content . replace ( LIST_ITEM_END_R , '\n\n' )
512
+ adjustedContent = trimEnd ( content ) + '\n\n'
513
513
} else {
514
514
state . inline = true
515
- adjustedContent = content . replace ( LIST_ITEM_END_R , '' )
515
+ adjustedContent = trimEnd ( content )
516
516
}
517
517
518
518
const result = parse ( adjustedContent , state )
@@ -576,7 +576,9 @@ const BLOCK_SYNTAXES = [
576
576
]
577
577
578
578
function trimEnd ( str : string ) {
579
- return str . replace ( / \s * $ / , '' )
579
+ let end = str . length
580
+ while ( end > 0 && str [ end - 1 ] <= ' ' ) end --
581
+ return str . slice ( 0 , end )
580
582
}
581
583
582
584
function containsBlockSyntax ( input : string ) {
@@ -1408,10 +1410,10 @@ export function compiler(
1408
1410
parse ( capture /*, parse, state*/ ) {
1409
1411
return {
1410
1412
lang : undefined ,
1411
- text : capture [ 0 ]
1412
- . replace ( / ^ { 4 } / gm , '' )
1413
- . replace ( / \n + $ / , '' )
1414
- . replace ( TEXT_UNESCAPE_R , '$1' ) ,
1413
+ text : trimEnd ( capture [ 0 ] . replace ( / ^ { 4 } / gm , '' ) ) . replace (
1414
+ TEXT_UNESCAPE_R ,
1415
+ '$1'
1416
+ ) ,
1415
1417
}
1416
1418
} ,
1417
1419
You can’t perform that action at this time.
0 commit comments