diff --git a/hyperlink/_url.py b/hyperlink/_url.py index de8aca06..81fc7fb0 100644 --- a/hyperlink/_url.py +++ b/hyperlink/_url.py @@ -1093,6 +1093,9 @@ def child(self, *segments): URL: A copy of the current URL with the extra path segments. """ + if not segments: + return self + segments = [_textcheck('path segment', s) for s in segments] new_segs = _encode_path_parts(segments, joined=False, maximal=False) new_path = self.path[:-1 if (self.path and self.path[-1] == u'') diff --git a/hyperlink/test/test_url.py b/hyperlink/test/test_url.py index 94a30d95..cbb08431 100644 --- a/hyperlink/test/test_url.py +++ b/hyperlink/test/test_url.py @@ -330,6 +330,13 @@ def test_childInitRoot(self): self.assertTrue(childURL.rooted) self.assertEqual("http://www.foo.com/c", childURL.to_text()) + def test_emptyChild(self): + """ + L{URL.child} without any new segments returns the original L{URL}. + """ + url = URL(host=u"www.foo.com") + self.assertEqual(url.child(), url) + def test_sibling(self): """ L{URL.sibling} of a L{URL} replaces the last path segment, but does not