Skip to content

Commit

Permalink
BUG: parse path without modifying query
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Oct 7, 2022
1 parent 4b1e369 commit c90fc5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions rasterio/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ class _ParsedPath(_Path):
@classmethod
def from_uri(cls, uri):
parts = urlparse(uri)
path = parts.path
path = pathlib.Path(parts.path).as_posix() if parts.path else parts.path
scheme = parts.scheme or None

if parts.query:
path += "?" + parts.query

if parts.scheme and parts.netloc:
path = parts.netloc + path

parts = path.split('!')
path = parts.pop() if parts else None
archive = parts.pop() if parts else None
return _ParsedPath(pathlib.Path(path).as_posix(), archive, scheme)
return _ParsedPath(path, archive, scheme)

@property
def name(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def test_parse_gdal():
assert _parse_path('GDAL:filepath:varname').path == 'GDAL:filepath:varname'


def test_parse_http_password():
"""Make sure password unmodified GH2602"""
parsed = _parse_path('https://foo.tif?bar=a//b')
assert parsed.path == 'foo.tif?bar=a//b'
assert parsed.archive is None
assert parsed.scheme == 'https'


@pytest.mark.skipif(sys.platform == 'win32', reason="Checking behavior on posix, not win32")
def test_parse_windows_path(monkeypatch):
"""Return Windows paths unparsed"""
Expand Down

0 comments on commit c90fc5a

Please sign in to comment.