From fdb0dbca4b824e1df00dc051e046ef1716e69a51 Mon Sep 17 00:00:00 2001 From: Kevin C Date: Wed, 7 Aug 2024 15:32:09 -0700 Subject: [PATCH] Coerce path into str for "String interface" For usages like: `url = furl('/foo') / 'user' / 12` --- furl/furl.py | 2 +- tests/test_furl.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/furl/furl.py b/furl/furl.py index cd6d710..95c4020 100644 --- a/furl/furl.py +++ b/furl/furl.py @@ -537,7 +537,7 @@ def add(self, path): elif is_iterable_but_not_string(path): # List interface. newsegments = path else: # String interface. - newsegments = self._segments_from_path(path) + newsegments = self._segments_from_path(str(path)) # Preserve the opening '/' if one exists already (self.segments # == ['']). diff --git a/tests/test_furl.py b/tests/test_furl.py index bc268c8..9e99867 100644 --- a/tests/test_furl.py +++ b/tests/test_furl.py @@ -289,6 +289,9 @@ def test_add(self): assert p.add(['e', 'f', 'e e', '']) == p assert p.isabsolute assert str(p) == '/a/b/c/d/e/f/e%20e/' + assert p.add(12) == p + assert p.isabsolute + assert str(p) == '/a/b/c/d/e/f/e%20e/12' f = furl.furl('http://sprop.ru') assert not f.path.isabsolute @@ -529,8 +532,11 @@ def test_itruediv(self): p /= 'c d/' assert str(p) == 'a/b/c%20d/' + p /= 12 + assert str(p) == 'a/b/c%20d/12' + p /= furl.Path('e') - assert str(p) == 'a/b/c%20d/e' + assert str(p) == 'a/b/c%20d/12/e' def test_truediv(self): p = furl.Path() @@ -539,10 +545,15 @@ def test_truediv(self): assert p1 is not p assert str(p1) == 'a' - p2 = p / 'a' / 'b' + p2 = p / 'a' / 12 assert p2 is not p + assert str(p2) == 'a/12' + + p3 = p / 'a' / 12 / 'b' + assert p3 is not p + assert str(p3) == 'a/12/b' + assert str(p) == '' - assert str(p2) == 'a/b' # Path objects should be joinable with other Path objects. p3 = furl.Path('e')