[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.
--- 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):
--- 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)
--- 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])