Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## python-markdown2 2.5.6 (not yet released)

- [pull #749] URL-encode destinations generated by the `link-patterns` extra (#55)
- [pull #746] Preserve query strings and fragments in `markdown-file-links` conversions, including reference-link targets.
- [pull #739] Fix `header-ids` extra putting sanitized HTML into header ids in safe mode, which allowed attribute injection (#649)
- [pull #732] Fix excessive CPU use in the inline HTML tokenizer on repeated unclosed tag fragments (#707)
Expand Down
3 changes: 2 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
from collections.abc import Collection
from enum import IntEnum, auto
from os import urandom
from urllib.parse import quote

# ---- type defs
_safe_mode = Literal['replace', 'escape']
Expand Down Expand Up @@ -3903,7 +3904,7 @@ def run(self, text: str):
continue

escaped_href = (
href.replace('"', '"') # b/c of attr quote
quote(href, safe=":/?#[]@!$&'()*+,;=%")
# To avoid markdown <em> and <strong>:
.replace('*', self.md._escape_table['*'])
.replace('_', self.md._escape_table['_']))
Expand Down
1 change: 1 addition & 0 deletions test/tm-cases/link_patterns_url_encoding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><a href="lorem%20foo%20bar%20ipsum">foo bar</a></p>
5 changes: 5 additions & 0 deletions test/tm-cases/link_patterns_url_encoding.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile(r"^(.*)$"), r"lorem \1 ipsum"),
],
}
1 change: 1 addition & 0 deletions test/tm-cases/link_patterns_url_encoding.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo bar
Loading