Commit c74ebecd authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Ensure listbox default parameter are loaded as UTF-8, not unicode

parent d5564ccf
......@@ -68,6 +68,17 @@ if REQUEST is None:\n
if response is None:\n
response = REQUEST.RESPONSE\n
\n
# http://stackoverflow.com/a/13105359\n
def byteify(string):\n
if isinstance(string, dict):\n
return {byteify(key): byteify(value) for key, value in string.iteritems()}\n
elif isinstance(string, list):\n
return [byteify(element) for element in string]\n
elif isinstance(string, unicode):\n
return string.encode(\'utf-8\')\n
else:\n
return string\n
\n
url_template_dict = {\n
"form_action": "%(traversed_document_url)s/%(action_id)s",\n
"traverse_generator": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
......@@ -954,7 +965,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# context.log(query)\n
catalog_kw = {}\n
if (default_param_json is not None):\n
catalog_kw = json.loads(urlsafe_b64decode(default_param_json))\n
catalog_kw = byteify(json.loads(urlsafe_b64decode(default_param_json)))\n
if (list_method is None):\n
callable_list_method = portal.portal_catalog\n
else:\n
......
......@@ -745,6 +745,23 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(len(result_dict['_embedded']['contents']), 0)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_default_param_json_param(self):
fake_request = do_fake_request("GET")
self.assertRaisesRegexp(
TypeError,
# "Unknown columns.*'\\xc3\\xaa'.",
"Unknown columns.*\\\\xc3\\\\xaa.*",
self.portal.web_site_module.hateoas.ERP5Document_getHateoas,
REQUEST=fake_request,
mode="search",
default_param_json='eyJcdTAwZWEiOiAiXHUwMGU4In0=')
class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
@simulate('Base_getRequestHeader', '*args, **kwargs',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment