diff options
author | Mehdi Abaakouk <sileht@sileht.net> | 2014-12-10 14:42:11 +0100 |
---|---|---|
committer | Mehdi Abaakouk <sileht@sileht.net> | 2014-12-11 07:35:18 +0100 |
commit | e9ded6acf09aa53521d89acfd781a10c060d447d (patch) | |
tree | d00e1a0a865c9a72b7406585e48b3370a4ba8d46 | |
parent | 2a69f5b505f0eb21623ecb521fefa18ea88eb958 (diff) | |
download | pecan-e9ded6acf09aa53521d89acfd781a10c060d447d.tar.gz |
Allows multiple parameters to be converted to list
Webob passed duplicates parameters to pecan, but pecan
take only the first one. This patch changes than and pass
the duplicated parameters as list to controller method.
Closes bug: #1401123
Change-Id: I8d0a7eda30a4c03cd85ed730ac3f08dde5e9aa56
-rw-r--r-- | pecan/core.py | 10 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 28 |
2 files changed, 33 insertions, 5 deletions
diff --git a/pecan/core.py b/pecan/core.py index 4a2c9be..173210b 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -504,22 +504,22 @@ class PecanBase(object): # fetch any parameters if req.method == 'GET': - params = dict(req.GET) + params = req.GET elif req.content_type in ('application/json', 'application/javascript'): try: if not isinstance(req.json, dict): raise TypeError('%s is not a dict' % req.json) - params = dict(NestedMultiDict(req.GET, req.json)) + params = NestedMultiDict(req.GET, req.json) except (TypeError, ValueError): - params = dict(req.params) + params = req.params else: - params = dict(req.params) + params = req.params # fetch the arguments for the controller args, varargs, kwargs = self.get_args( state, - params, + params.mixed(), remainder, cfg['argspec'], im_self diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index a18981c..cca494c 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -12,6 +12,7 @@ from webob.exc import HTTPNotFound from webtest import TestApp import six from six import b as b_ +from six import u as u_ from six.moves import cStringIO as StringIO from pecan import ( @@ -872,6 +873,33 @@ class TestControllerArguments(PecanTestCase): assert r.status_int == 200 assert r.body == b_('variable_all: 7, day=12, id=seven, month=1') + def test_duplicate_query_parameters_GET(self): + r = self.app_.get('/variable_kwargs?list=1&list=2') + l = [u_('1'), u_('2')] + assert r.status_int == 200 + assert r.body == b_('variable_kwargs: list=%s' % l) + + def test_duplicate_query_parameters_POST(self): + r = self.app_.post('/variable_kwargs', + {'list': ['1', '2']}) + l = [u_('1'), u_('2')] + assert r.status_int == 200 + assert r.body == b_('variable_kwargs: list=%s' % l) + + def test_duplicate_query_parameters_POST_mixed(self): + r = self.app_.post('/variable_kwargs?list=1&list=2', + {'list': ['3', '4']}) + l = [u_('1'), u_('2'), u_('3'), u_('4')] + assert r.status_int == 200 + assert r.body == b_('variable_kwargs: list=%s' % l) + + def test_duplicate_query_parameters_POST_mixed_json(self): + r = self.app_.post('/variable_kwargs?list=1&list=2', + {'list': 3}) + l = [u_('1'), u_('2'), u_('3')] + assert r.status_int == 200 + assert r.body == b_('variable_kwargs: list=%s' % l) + def test_no_remainder(self): try: r = self.app_.get('/eater') |