diff options
author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2019-07-11 08:20:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-11 08:20:20 -0500 |
commit | df03b63b7144b8bdb726f452d74795b696f618ba (patch) | |
tree | 8d7e81c3dcf0fecd39c4f00c8947ab49de23e90e | |
parent | 68064e2e8f60687674071f9c791603b0ae6a76a4 (diff) | |
parent | abb1308fa8b7c50eb79e9f07ee448a76c7449847 (diff) | |
download | uritemplates-df03b63b7144b8bdb726f452d74795b696f618ba.tar.gz |
Merge pull request #43 from metatoaster/list_of_empty
Correct handling of empty/undef in list values
-rw-r--r-- | tests/test_uritemplate.py | 46 | ||||
-rw-r--r-- | uritemplate/variable.py | 6 |
2 files changed, 48 insertions, 4 deletions
diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index 7448be0..f67ad26 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -464,6 +464,52 @@ class TestURITemplate(RFCTemplateExamples('RFCMeta', (TestCase,), {})): None ) + def test_label_path_expansion_explode_slash(self): + t = URITemplate('{/foo*}') + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None, None], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one'], True, '/'), 'one' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', None, 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [''], True, '/'), '' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['', ''], True, '/'), '/' + ) + + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': ''}, True, '/'), 'one=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': '', 'two': ''}, True, '/'), 'one=/two=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': 'two'}, True, '/'), 'two=two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': None}, True, '/'), None + ) + def test_semi_path_expansion(self): t = URITemplate('{foo}') v = t.variables[0] diff --git a/uritemplate/variable.py b/uritemplate/variable.py index a3bd4ce..ce3f652 100644 --- a/uritemplate/variable.py +++ b/uritemplate/variable.py @@ -200,10 +200,8 @@ class URIVariable(object): if not explode: join_str = ',' - expanded = join_str.join( - quote(v, safe) for v in value if value is not None - ) - return expanded if expanded else None + fragments = [quote(v, safe) for v in value if v is not None] + return join_str.join(fragments) if fragments else None if dict_test(value) or tuples: items = items or sorted(value.items()) |