Skip to content

Commit a6d4321

Browse files
committed
Fix asteris emphasis regex CVE-2022-34749
1 parent 5638e46 commit a6d4321

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

mistune/inline_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class InlineParser(ScannerParser):
6464
#: _emphasis_ __strong__
6565
ASTERISK_EMPHASIS = (
6666
r'(\*{1,2})(?=[^\s*])('
67-
r'(?:\\[\\*]|[^*])*'
68-
r'(?:' + ESCAPE_TEXT + r'|[^\s*]))\1'
67+
r'(?:(?:(?<!\\)(?:\\\\)*\*)|[^*])+'
68+
r')(?<!\\)\1'
6969
)
7070
UNDERSCORE_EMPHASIS = (
7171
r'\b(_{1,2})(?=[^\s_])([\s\S]*?'

tests/fixtures/non-commonmark.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
<p>[link [foo [bar]]](/uri)</p>
1313
````````````````````````````````
1414

15-
```````````````````````````````` example
16-
[link *foo **bar** `#`*](/uri)
17-
.
18-
<p><a href="/uri">link *foo <strong>bar</strong> <code>#</code>*</a></p>
19-
````````````````````````````````
20-
2115
```````````````````````````````` example
2216
[foo [bar](/uri)](/uri)
2317
.
@@ -48,14 +42,6 @@
4842
<p><a href="uri">foo&lt;http://example.com/?search=</a>&gt;</p>
4943
````````````````````````````````
5044

51-
```````````````````````````````` example
52-
[link *foo **bar** `#`*][ref]
53-
54-
[ref]: /uri
55-
.
56-
<p><a href="/uri">link *foo <strong>bar</strong> <code>#</code>*</a></p>
57-
````````````````````````````````
58-
5945
```````````````````````````````` example
6046
[foo [bar](/uri)][ref]
6147

0 commit comments

Comments
 (0)