FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: decode percent-encoded unreserved chars before resolving dot segments in normalize by gaoflow · Pull Request #195 · python-hyper/hyperlink · GitHub

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions src/hyperlink/_url.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,9 @@ def _dec_unres(target):

if path:
if self.path:
kw["path"] = [
_dec_unres(p) for p in _resolve_dot_segments(self.path)
]
kw["path"] = _resolve_dot_segments(
[_dec_unres(p) for p in self.path]
)
else:
kw["path"] = (u"",)
if query:
Expand Down
21 changes: 21 additions & 0 deletions src/hyperlink/test/test_url.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,27 @@ def test_normalize(self):
== "ftp://%25:%25@/%25%25%25/%25a%25b?%25=%25%25#%25"
)

def test_normalize_percent_encoded_dot_segments(self):
# type: () -> None
# RFC 3986 Section 6.2.2.2: percent-encoded unreserved characters
# should be decoded BEFORE resolving dot segments.
# %2e = '.' (unreserved), so %2e%2e should become '..' and
# be resolved to the parent directory.
url = URL.from_text("http://example.com/%2e%2e/foo")
norm = url.normalize()
assert norm.path == ("foo",)
assert norm.to_text() == "http://example.com/foo"

url2 = URL.from_text("http://example.com/%2e/foo")
norm2 = url2.normalize()
assert norm2.path == ("foo",)
assert norm2.to_text() == "http://example.com/foo"

url3 = URL.from_text("http://example.com/foo/%2e%2e/bar")
norm3 = url3.normalize()
assert norm3.path == ("bar",)
assert norm3.to_text() == "http://example.com/bar"

def test_str(self):
# type: () -> None

Expand Down

Back | FazBrowse Home | New Git URL