Skip to content

Commit 500e69e

Browse files
authored
👌 fix possible ReDOS in newline rule (#275)
Implements upstream: markdown-it/markdown-it@ffc49ab
1 parent 84dcefe commit 500e69e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

markdown_it/port.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- package: markdown-it/markdown-it
2-
version: 12.3.1
3-
commit: 76469e83dc1a1e3ed943b483b554003a666bddf7
4-
date: Jan 7, 2022
2+
version: 12.3.2
3+
commit: d72c68b520cedacae7878caa92bf7fe32e3e0e6f
4+
date: Jan 8, 2022
55
notes:
66
- Rename variables that use python built-in names, e.g.
77
- `max` -> `maximum`

markdown_it/rules_inline/newline.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
# Proceess '\n'
2-
import re
3-
1+
"""Proceess '\n'."""
42
from ..common.utils import charStrAt, isStrSpace
53
from .state_inline import StateInline
64

7-
endSpace = re.compile(r" +$")
8-
95

106
def newline(state: StateInline, silent: bool) -> bool:
117
pos = state.pos
@@ -23,7 +19,12 @@ def newline(state: StateInline, silent: bool) -> bool:
2319
if not silent:
2420
if pmax >= 0 and charStrAt(state.pending, pmax) == " ":
2521
if pmax >= 1 and charStrAt(state.pending, pmax - 1) == " ":
26-
state.pending = endSpace.sub("", state.pending)
22+
# Find whitespaces tail of pending chars.
23+
ws = pmax - 1
24+
while ws >= 1 and charStrAt(state.pending, ws - 1) == " ":
25+
ws -= 1
26+
state.pending = state.pending[:ws]
27+
2728
state.push("hardbreak", "br", 0)
2829
else:
2930
state.pending = state.pending[:-1]

0 commit comments

Comments
 (0)