Skip to content

Commit 395f690

Browse files
allanleiwcooley
andauthored
Chaining boltons.urlutils.URL.navigate() results in TypeError (#298)
* Add test cases for issue #158 * Fix TypeError w/issue #158 and PR #159 This makes only one more test pass (now only 3 failing) but at least prevents the `TypeError` when attempting to add a `list` and a `tuple`. * Fix: Expected results should be `https://host/b` * Provide parameters via `path` * Move test case after `test_navigate` Co-authored-by: Wil Cooley <[email protected]>
1 parent 270e974 commit 395f690

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

boltons/urlutils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ def navigate(self, dest):
685685
if dest.path.startswith(u'/'): # absolute path
686686
new_path_parts = list(dest.path_parts)
687687
else: # relative path
688-
new_path_parts = self.path_parts[:-1] + dest.path_parts
688+
new_path_parts = list(self.path_parts[:-1]) \
689+
+ list(dest.path_parts)
689690
else:
690691
new_path_parts = list(self.path_parts)
691692
if not query_params:

tests/test_urlutils.py

+19
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,25 @@ def test_navigate():
313313
assert navd.to_text() == _dest_text
314314

315315

316+
@pytest.mark.parametrize(
317+
('expected', 'base', 'paths'), [
318+
('https://host/b', 'https://host', ('a', '/b', )),
319+
('https://host/b', 'https://host', ('a', 'b', )),
320+
('https://host/a/b', 'https://host', ('a/', 'b', )),
321+
('https://host/b', 'https://host', ('/a', 'b', )),
322+
('https://host/a/b', 'https://host/a/', (None, 'b', )),
323+
('https://host/b', 'https://host/a', (None, 'b', )),
324+
])
325+
def test_chained_navigate(expected, base, paths):
326+
"""Chained :meth:`navigate` calls produces correct results."""
327+
url = URL(base)
328+
329+
for path in paths:
330+
url = url.navigate(path)
331+
332+
assert expected == url.to_text()
333+
334+
316335
# TODO: RFC3986 6.2.3 (not just for query add, either)
317336
# def test_add_query():
318337
# url = URL('http://www.example.com')

0 commit comments

Comments
 (0)