# HG changeset patch # User Florent Cayré # Date 1484880883 -3600 # Node ID 244cd7f407b86fc8dee91daa3c2a03f0c6f75634 # Parent 7904fe436e82b31d5a38647d015d2997b117dc30 [uilib] Fix incorrect serialization of python dicts into javascript objects Valid javascript object keys must be surrounded by quotes unless they are valid javascript identifiers. Valid identifiers are a defined by complex and changing specs, so it is much simpler to always use quotes. Closes #17046704. diff -r 7904fe436e82 -r 244cd7f407b8 cubicweb/test/unittest_uilib.py --- a/cubicweb/test/unittest_uilib.py Thu Jan 12 13:40:25 2017 +0100 +++ b/cubicweb/test/unittest_uilib.py Fri Jan 20 03:54:43 2017 +0100 @@ -174,8 +174,10 @@ 'cw.pouet(1,"2").pouet(null)') self.assertEqual(str(uilib.js.cw.pouet(1, cwutils.JSString("$")).pouet(None)), 'cw.pouet(1,$).pouet(null)') - self.assertEqual(str(uilib.js.cw.pouet(1, {'callback': cwutils.JSString("cw.cb")}).pouet(None)), - 'cw.pouet(1,{callback: cw.cb}).pouet(null)') + self.assertEqual( + str(uilib.js.cw.pouet( + 1, {'call back': cwutils.JSString("cw.cb")}).pouet(None)), + 'cw.pouet(1,{"call back": cw.cb}).pouet(null)') def test_embedded_css(self): diff -r 7904fe436e82 -r 244cd7f407b8 cubicweb/utils.py --- a/cubicweb/utils.py Thu Jan 12 13:40:25 2017 +0100 +++ b/cubicweb/utils.py Fri Jan 20 03:54:43 2017 +0100 @@ -534,7 +534,7 @@ it = sorted(d.items()) else: it = d.items() - res = [key + ': ' + js_dumps(val, predictable) + res = [js_dumps(key, predictable) + ': ' + js_dumps(val, predictable) for key, val in it] return '{%s}' % ', '.join(res) diff -r 7904fe436e82 -r 244cd7f407b8 cubicweb/web/test/unittest_web.py --- a/cubicweb/web/test/unittest_web.py Thu Jan 12 13:40:25 2017 +0100 +++ b/cubicweb/web/test/unittest_web.py Fri Jan 20 03:54:43 2017 +0100 @@ -51,7 +51,7 @@ cbname = url.split()[1][:-2] self.assertMultiLineEqual( 'function %s() { $("#foo").loadxhtml("http://testing.fr/cubicweb/ajax?%s",' - '{pageid: "%s"},"get","replace"); }' % + '{"pageid": "%s"},"get","replace"); }' % (cbname, qs, req.pageid), req.html_headers.post_inlined_scripts[0])