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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ def click(self, href=u""):
if clicked.absolute:
return clicked
else:
clicked = self
clicked = self.replace(fragment=u"")

query = clicked.query
if clicked.scheme and not clicked.rooted:
Expand Down
11 changes: 11 additions & 0 deletions src/hyperlink/test/test_decoded_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@


class TestURL(HyperlinkTestCase):
def test_click_empty_reference_clears_fragment(self):
# type: () -> None
base = DecodedURL.from_text("http://example.com/a/b?x=1#old")
expected = "http://example.com/a/b?x=1"
assert base.click("").to_text() == expected
assert base.click().to_text() == expected
assert base.click("") == base.click(URL())
assert base.click("") == base.click(DecodedURL())
assert base.click("#new").fragment == "new"
assert base.fragment == "old"

def test_durl_basic(self):
# type: () -> None
bdurl = DecodedURL.from_text(BASIC_URL)
Expand Down
15 changes: 15 additions & 0 deletions src/hyperlink/test/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,21 @@ def test_click(self):
u3 = u.click(u2)
self.assertEqual(u3.to_text(), "http://localhost/foo/bar")

def test_click_empty_reference_clears_fragment(self):
# type: () -> None
for text, expected in (
("http://example.com/a/b?x=1#old", "http://example.com/a/b?x=1"),
("http://example.com/a/../b#old", "http://example.com/b"),
("http://example.com/#old", "http://example.com/"),
):
base = URL.from_text(text)
assert base.click("").to_text() == expected
assert base.click().to_text() == expected
assert base.click("") == base.click(URL())
assert base.click("#new").fragment == "new"
assert base.click("#").fragment == ""
assert base.fragment == "old"

def test_clickRFC3986(self):
# type: () -> None
"""
Expand Down