diff --git a/boltons/urlutils.py b/boltons/urlutils.py index c96ec08e..b2397497 100644 --- a/boltons/urlutils.py +++ b/boltons/urlutils.py @@ -654,7 +654,8 @@ def navigate(self, dest): if dest.path.startswith(u'/'): # absolute path new_path_parts = list(dest.path_parts) else: # relative path - new_path_parts = self.path_parts[:-1] + dest.path_parts + new_path_parts = list(self.path_parts[:-1]) \ + + list(dest.path_parts) else: new_path_parts = list(self.path_parts) if not query_params: diff --git a/tests/test_urlutils.py b/tests/test_urlutils.py index e1570ab1..e71755ec 100644 --- a/tests/test_urlutils.py +++ b/tests/test_urlutils.py @@ -268,6 +268,23 @@ def test_rel_navigate(): return +@pytest.mark.parametrize( + ('expected', 'base', 'a', 'b'), [ + ('https://host/b', 'https://host', 'a', '/b'), + ('https://host/a/b', 'https://host', 'a', 'b'), + ('https://host/a/b', 'https://host', 'a/', 'b'), + ('https://host/a/b', 'https://host', '/a', 'b'), + ('https://host/a/b', 'https://host/a/', None, 'b'), + ('https://host/a/b', 'https://host/a', None, 'b'), +]) +def test_chained_navigate(expected, base, a, b): + """Chained :meth:`navigate` calls produces correct results.""" + if a is not None: + assert expected == URL(base).navigate(a).navigate(b).to_text() + else: + assert expected == URL(base).navigate(b).to_text() + + def test_navigate(): orig_text = u'http://a.b/c/d?e#f' orig = URL(orig_text)