Skip to content

Commit b32bb80

Browse files
authored
Merge pull request #17 from lazka/urlunparse-fix
uri2fsn: fix handling of relative paths with newer Python
2 parents 48dadce + 031d054 commit b32bb80

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: [ubuntu-20.04, macos-13, windows-2019]
13-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.10']
13+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', 'pypy3.10']
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Set up Python ${{ matrix.python-version }}
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install pytest hypothesis flake8 coverage
23+
pip install pytest hypothesis flake8 coverage setuptools
2424
- name: Run tests on Unix
2525
if: ${{ matrix.os != 'windows-2019' }}
2626
run: |

senf/_fsnative.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,11 @@ def uri2fsn(uri):
541541
if not parsed_path:
542542
raise ValueError("Invalid file URI: %r" % uri)
543543

544-
uri = urlunparse(parsed)[7:]
544+
uri = urlunparse(parsed)[5:]
545+
if not parsed_path.startswith("/") and uri.startswith("/"):
546+
uri = uri.lstrip("/")
547+
if not netloc and uri.startswith("///"):
548+
uri = uri[2:]
545549

546550
if is_win:
547551
try:
@@ -556,8 +560,6 @@ def uri2fsn(uri):
556560
path += unquote(rest)
557561
else:
558562
path += unquote(rest, encoding="utf-8", errors="surrogatepass")
559-
if netloc or parsed_path.startswith("//"):
560-
path = "\\\\" + path
561563
if PY2:
562564
path = path.decode("utf-8")
563565
if u"\x00" in path:

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ def test_uri2fsn():
10051005
assert isinstance(uri2fsn(u"file:///foo"), fsnative)
10061006
assert \
10071007
uri2fsn("file:///foo-%E1%88%B4") == path2fsn(b"/foo-\xe1\x88\xb4")
1008-
assert uri2fsn("file:NOPE") == fsnative(u"/NOPE")
1008+
assert uri2fsn("file:NOPE") == fsnative(u"NOPE")
10091009
assert uri2fsn("file:/NOPE") == fsnative(u"/NOPE")
10101010
with pytest.raises(ValueError):
10111011
assert uri2fsn("file://NOPE")
@@ -1015,7 +1015,7 @@ def test_uri2fsn():
10151015
else:
10161016
assert uri2fsn("file:///C:/%ED%A0%80") == fsnative(u"C:\\\ud800")
10171017
assert uri2fsn("file:///C:/%20") == "C:\\ "
1018-
assert uri2fsn("file:NOPE") == "\\NOPE"
1018+
assert uri2fsn("file:NOPE") == "NOPE"
10191019
assert uri2fsn("file:/NOPE") == "\\NOPE"
10201020
with pytest.raises(ValueError):
10211021
assert uri2fsn(u"file:///C:/%00")

0 commit comments

Comments
 (0)