Skip to content

Commit

Permalink
Fix for urlunparse in latest Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Sep 17, 2024
1 parent 6d2d8e5 commit be6eeba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- **NEW**: MagicLink: Change social process to support `x` instead of `twitter`. `twitter` is still recognized but is
now deprecated and will be removed at a future time.
- **FIX**: PathConverter: Fixes for latest changes in Python regarding `urlunparse`.

## 10.9

Expand Down
6 changes: 5 additions & 1 deletion pymdownx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from functools import wraps
import warnings

RE_WIN_DRIVE = re.compile(r'^[A-Za-z]:.*$')
RE_WIN_DRIVE_LETTER = re.compile(r"^[A-Za-z]$")
RE_WIN_DRIVE_PATH = re.compile(r"^[A-Za-z]:(?:\\.*)?$")
RE_URL = re.compile('(http|ftp)s?|data|mailto|tel|news')
Expand Down Expand Up @@ -53,7 +54,10 @@ def is_mac(): # pragma: no cover
def url2path(path):
"""Path to URL."""

return url2pathname(path)
path = url2pathname(path)
if is_win() and RE_WIN_DRIVE.match(path):
path = '/' + path
return path


def path2url(url):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_extensions/test_pathconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,15 @@ def test_windows_root_conversion(self):
r'<p><img alt="picture" src="file:///C:/Some/fake/path/extensions/_assets/bg.png" /></p>'
)
else:
from urllib.parse import urlunparse

if urlunparse(('file', '', 'c:/test', '', '', '')) == 'file:c:/test':
result = r'<p><img alt="picture" src="file:C%3A/Some/fake/path/extensions/_assets/bg.png" /></p>'
else:
result = r'<p><img alt="picture" src="file:///C%3A/Some/fake/path/extensions/_assets/bg.png" /></p>'
self.check_markdown(
r'![picture](./extensions/_assets/bg.png)',
r'<p><img alt="picture" src="file:///C%3A/Some/fake/path/extensions/_assets/bg.png" /></p>'
result
)


Expand Down

0 comments on commit be6eeba

Please sign in to comment.