From a793c1d11a3ada1508f0c0979eb317afe2b94ee4 Mon Sep 17 00:00:00 2001 From: Timur Date: Tue, 1 Jul 2014 22:20:18 +0400 Subject: Query string arg names starting with equal sign I use %3D (URL encoded equal sign) prefix in argument name for filter parametrization: GET /users?%3Dphone_number=1234567 Since request_param supports matching specific values with equal sign syntax, this doesn't work when route registered with explicit filter args names in request_param. --- pyramid/config/predicates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/config/predicates.py b/pyramid/config/predicates.py index 967f2eeee..128c3ab7b 100644 --- a/pyramid/config/predicates.py +++ b/pyramid/config/predicates.py @@ -70,7 +70,7 @@ class RequestParamPredicate(object): for p in val: k = p v = None - if '=' in p: + if '=' in p and not (p.startswith('=') or p.endswith('=')): k, v = p.split('=', 1) k, v = k.strip(), v.strip() reqs.append((k, v)) -- cgit v1.2.3 From 8668dba51714a6e96d27fcd05338e0124036ef3f Mon Sep 17 00:00:00 2001 From: Timur Date: Wed, 2 Jul 2014 08:23:04 +0400 Subject: Restrict request_param equal sign syntax --- pyramid/config/predicates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/config/predicates.py b/pyramid/config/predicates.py index 128c3ab7b..fbd214b15 100644 --- a/pyramid/config/predicates.py +++ b/pyramid/config/predicates.py @@ -70,7 +70,7 @@ class RequestParamPredicate(object): for p in val: k = p v = None - if '=' in p and not (p.startswith('=') or p.endswith('=')): + if '=' in p and not p.startswith('='): k, v = p.split('=', 1) k, v = k.strip(), v.strip() reqs.append((k, v)) -- cgit v1.2.3 From 00f80cd6d2301720792b6448909aaed3895821e7 Mon Sep 17 00:00:00 2001 From: Timur Izhbulatov Date: Wed, 2 Jul 2014 11:44:33 +0400 Subject: Tests for request_param name starting with '=' --- pyramid/tests/test_config/test_predicates.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyramid/tests/test_config/test_predicates.py b/pyramid/tests/test_config/test_predicates.py index 1cd6050bf..46516f518 100644 --- a/pyramid/tests/test_config/test_predicates.py +++ b/pyramid/tests/test_config/test_predicates.py @@ -144,6 +144,10 @@ class TestRequestParamPredicate(unittest.TestCase): inst = self._makeOne('abc') self.assertEqual(inst.text(), 'request_param abc') + def test_text_exists_equal_sign(self): + inst = self._makeOne('=abc') + self.assertEqual(inst.text(), 'request_param =abc') + def test_text_withval(self): inst = self._makeOne('abc= 1') self.assertEqual(inst.text(), 'request_param abc=1') @@ -152,10 +156,18 @@ class TestRequestParamPredicate(unittest.TestCase): inst = self._makeOne(('abc= 1', 'def')) self.assertEqual(inst.text(), 'request_param abc=1,def') + def test_text_multi_equal_sign(self): + inst = self._makeOne(('abc= 1', '=def')) + self.assertEqual(inst.text(), 'request_param =def,abc=1') + def test_phash_exists(self): inst = self._makeOne('abc') self.assertEqual(inst.phash(), 'request_param abc') + def test_phash_exists_equal_sign(self): + inst = self._makeOne('=abc') + self.assertEqual(inst.phash(), 'request_param =abc') + def test_phash_withval(self): inst = self._makeOne('abc= 1') self.assertEqual(inst.phash(), "request_param abc=1") -- cgit v1.2.3 From afa8a7457384aeb2c621b65f3acccce1ec28c3b9 Mon Sep 17 00:00:00 2001 From: Timur Izhbulatov Date: Tue, 14 Apr 2015 08:42:05 +0400 Subject: Request params starting with '=' may have value --- pyramid/config/predicates.py | 7 +++++-- pyramid/tests/test_config/test_predicates.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pyramid/config/predicates.py b/pyramid/config/predicates.py index fbd214b15..d87fd1aae 100644 --- a/pyramid/config/predicates.py +++ b/pyramid/config/predicates.py @@ -70,8 +70,11 @@ class RequestParamPredicate(object): for p in val: k = p v = None - if '=' in p and not p.startswith('='): - k, v = p.split('=', 1) + if '=' in p: + if p.startswith('='): + k, v = p.rsplit('=', 1) + else: + k, v = p.split('=', 1) k, v = k.strip(), v.strip() reqs.append((k, v)) self.val = val diff --git a/pyramid/tests/test_config/test_predicates.py b/pyramid/tests/test_config/test_predicates.py index 46516f518..ee24de093 100644 --- a/pyramid/tests/test_config/test_predicates.py +++ b/pyramid/tests/test_config/test_predicates.py @@ -157,8 +157,8 @@ class TestRequestParamPredicate(unittest.TestCase): self.assertEqual(inst.text(), 'request_param abc=1,def') def test_text_multi_equal_sign(self): - inst = self._makeOne(('abc= 1', '=def')) - self.assertEqual(inst.text(), 'request_param =def,abc=1') + inst = self._makeOne(('abc= 1', '=def= 2')) + self.assertEqual(inst.text(), 'request_param =def=2,abc=1') def test_phash_exists(self): inst = self._makeOne('abc') -- cgit v1.2.3 From fbb98c6ee76dc3ea6529d53a3ebdbb3e97dd7d1d Mon Sep 17 00:00:00 2001 From: Timur Izhbulatov Date: Mon, 20 Apr 2015 12:13:01 +0400 Subject: Update CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index c77d3e92c..92f109dfd 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -232,3 +232,5 @@ Contributors - Amit Mane, 2014/01/23 - Fenton Travers, 2014/05/06 + +- Timur Izhbulatov, 2015/04/14 -- cgit v1.2.3