File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1619,6 +1619,12 @@ def click(self, href=u""):
16191619 else :
16201620 clicked = self
16211621
1622+ if clicked .uses_netloc :
1623+ return clicked .replace (
1624+ scheme = clicked .scheme or self .scheme ,
1625+ path = _resolve_dot_segments (clicked .path ),
1626+ )
1627+
16221628 query = clicked .query
16231629 if clicked .scheme and not clicked .rooted :
16241630 # Schemes with relative paths are not well-defined. RFC 3986 calls
Original file line number Diff line number Diff line change @@ -412,6 +412,29 @@ def test_sibling(self):
412412 urlpath .sibling ("sister" ).to_text (),
413413 )
414414
415+ def test_click_network_path_replaces_authority (self ):
416+ # type: () -> None
417+ base = URL .from_text ("http://user:password@example.com:8080/old?q=base" )
418+ for href , expected in [
419+ ("//other.example/new" , "http://other.example/new" ),
420+ ("//other.example" , "http://other.example" ),
421+ ("//other.example?x=1" , "http://other.example/?x=1" ),
422+ ("//other.example:0/new" , "http://other.example:0/new" ),
423+ ("//newuser@other.example/new" , "http://newuser@other.example/new" ),
424+ ("//other.example/a/../new" , "http://other.example/new" ),
425+ ]:
426+ self .assertEqual (
427+ base .click (href ).to_text (with_password = True ), expected
428+ )
429+ self .assertEqual (
430+ base .click ("/new" ).to_text (with_password = True ),
431+ "http://user:password@example.com:8080/new" ,
432+ )
433+ self .assertEqual (
434+ base .to_text (with_password = True ),
435+ "http://user:password@example.com:8080/old?q=base" ,
436+ )
437+
415438 def test_click (self ):
416439 # type: () -> None
417440 """
You can’t perform that action at this time.
0 commit comments