From c8a91c6fa1eb4daa6be6dc7098518345bc6aa9bb Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 14 Dec 2008 04:00:07 +0000 Subject: Backwards Incompatibilities - URL-quote "extra" element names passed in as ``**elements`` to the ``traversal.model_url`` API. If any of these names is a Unicode string, encode it to UTF-8 before URL-quoting. This is a slight backwards incompatibility that will impact you if you were already UTF-8 encoding or URL-quoting the values you passed in as ``elements`` to this API. Bugfixes - UTF-8 encode each segment in the model path used to generate a URL before url-quoting it within the ``traversal.model_url`` API. This is a bugfix, as Unicode cannot always be successfully URL-quoted. --- repoze/bfg/tests/test_traversal.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'repoze/bfg/tests/test_traversal.py') diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 2c02d7d63..32be1ebbb 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -256,6 +256,45 @@ class ModelURLTests(unittest.TestCase): result = self._callFUT(other, request) self.assertEqual(result, 'http://example.com:5432/nonroot%20object/') + def test_unicode_mixed_with_bytes_in_model_names(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = None + one = DummyContext() + one.__parent__ = root + one.__name__ = unicode('La Pe\xc3\xb1a', 'utf-8') + two = DummyContext() + two.__parent__ = one + two.__name__ = 'La Pe\xc3\xb1a' + request = DummyRequest() + request.application_url = 'http://example.com:5432' + result = self._callFUT(two, request) + self.assertEqual(result, + 'http://example.com:5432/La%20Pe%C3%B1a/La%20Pe%C3%B1a/') + + def test_unicode_in_element_names(self): + uc = unicode('La Pe\xc3\xb1a', 'utf-8') + root = DummyContext() + root.__parent__ = None + root.__name__ = None + one = DummyContext() + one.__parent__ = root + one.__name__ = uc + request = DummyRequest() + request.application_url = 'http://example.com:5432' + result = self._callFUT(one, request, uc) + self.assertEqual(result, + 'http://example.com:5432/La%20Pe%C3%B1a/La%20Pe%C3%B1a') + + def test_element_names_url_quoted(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = None + request = DummyRequest() + request.application_url = 'http://example.com:5432' + result = self._callFUT(root, request, 'a b c') + self.assertEqual(result, 'http://example.com:5432/a%20b%20c') + class FindRootTests(unittest.TestCase): def _callFUT(self, context): from repoze.bfg.traversal import find_root -- cgit v1.2.3