Skip to content

Commit

Permalink
Merge pull request #564 from Crozzers/incomplete-html-comment-in-safe…
Browse files Browse the repository at this point in the history
…-mode

Fix incomplete comments in safe mode not being escaped (#563)
  • Loading branch information
nicholasserra authored Jan 3, 2024
2 parents b94feac + 4518c23 commit bb9d6b4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [pull #559] Allow cuddled tables (#557)
- [pull #560] Fix `markdown-in-html` not always splitting HTML tags into separate lines (#558)
- [pull #564] Fix incomplete comments in safe mode not being escaped (#563)


## python-markdown2 2.4.12
Expand Down
2 changes: 1 addition & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ def _encode_amps_and_angles(self, text):
text = self._naked_gt_re.sub('>', text)
return text

_incomplete_tags_re = re.compile(r"<(/?\w+?(?!\w)\s*?.+?[\s/]+?)")
_incomplete_tags_re = re.compile(r"<(!--|/?\w+?(?!\w)\s*?.+?[\s/]+?)")

def _encode_incomplete_tags(self, text):
if self.safe_mode not in ("replace", "escape"):
Expand Down
2 changes: 2 additions & 0 deletions test/tm-cases/basic_safe_mode_escape.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
<p>&lt;div&gt;yowzer!&lt;/div&gt;</p>

<p>blah</p>

<p><em>foo</em> &lt;!-- <em>bar</em></p>
3 changes: 3 additions & 0 deletions test/tm-cases/basic_safe_mode_escape.text
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ blah <img src="dangerous"> blah
<div>yowzer!</div>

blah


*foo* <!-- *bar*

0 comments on commit bb9d6b4

Please sign in to comment.