Skip to content

Commit

Permalink
Merge pull request #14 from quodlibet/legacy-unc-uri
Browse files Browse the repository at this point in the history
uri2fsn: Handle a subset of legacy UNC file URIs
  • Loading branch information
lazka committed May 9, 2020
2 parents a2bf050 + caa9e76 commit f3bb4cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions senf/_fsnative.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ def uri2fsn(uri):
parsed = urlparse(uri)
scheme = parsed.scheme
netloc = parsed.netloc
path = parsed.path
parsed_path = parsed.path

if scheme != "file":
raise ValueError("Not a file URI: %r" % uri)

if not path:
if not parsed_path:
raise ValueError("Invalid file URI: %r" % uri)

uri = urlunparse(parsed)[7:]
Expand All @@ -556,7 +556,7 @@ def uri2fsn(uri):
path += unquote(rest)
else:
path += unquote(rest, encoding="utf-8", errors="surrogatepass")
if netloc:
if netloc or parsed_path.startswith("//"):
path = "\\\\" + path
if PY2:
path = path.decode("utf-8")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,10 @@ def test_uri2fsn():
assert uri2fsn(u"file://UNC/foo/bar") == u"\\\\UNC\\foo\\bar"
assert uri2fsn(u"file://\u1234/\u4321") == u"\\\\\u1234\\\u4321"

# Also handle legacy UNC URIs
assert uri2fsn(u"file:////UNC/foo") == u"\\\\UNC\\foo"
assert fsn2uri(uri2fsn(u"file:////UNC/foo")) == u"file://UNC/foo"

with pytest.raises(TypeError):
uri2fsn(object()) # type: ignore

Expand Down

0 comments on commit f3bb4cb

Please sign in to comment.