# HG changeset patch # User Alain Leufroy <alain@leufroy.fr> # Date 1427466574 -3600 # Node ID da1cb2b12fe1d60f3c575d5720dfbe70cb1f5b66 # Parent f92823a66f18b6bfe98c3ee3b8fbaeaacd76d6c0 [uilib] `uilib.js` helper now honors explicit JSString (closes #4959538) Previously, if a JSString was inside a nested container (i.e. list or dict), it was handled as a string, not a verbatim js chunk (see docstring and test). So the following code:: >>> str(js.cw.pouet(1, {'callback': JSString('cw.mycallback')}) resulted in:: "cw.pouet(1, {'callback': 'cw.mycallback')})" while we expect (note the removed quotes):: "cw.pouet(1, {'callback': cw.mycallback)})" We use ``cubiweb.utils.js_dumps`` instead of ``cubicweb.utils.json_dumps`` which is aware of JSString. diff -r f92823a66f18 -r da1cb2b12fe1 test/unittest_uilib.py --- a/test/unittest_uilib.py Tue Apr 07 17:08:53 2015 +0200 +++ b/test/unittest_uilib.py Fri Mar 27 15:29:34 2015 +0100 @@ -30,7 +30,7 @@ from logilab.common.testlib import DocTest, TestCase, unittest_main -from cubicweb import uilib +from cubicweb import uilib, utils as cwutils lxml_version = pkg_resources.get_distribution('lxml').version.split('.') @@ -171,6 +171,11 @@ 'cw.pouet(1,"2")') self.assertEqual(str(uilib.js.cw.pouet(1, "2").pouet(None)), '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)') + def test_embedded_css(self): incoming = u"""voir le ticket <style type="text/css">@font-face { font-family: "Cambria"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 10pt; font-size: 12pt; font-family: "Times New Roman"; }a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }a:visited, span.MsoHyperlinkFollowed { color: purple; text-decoration: underline; }div.Section1 { page: Section1; }</style></p><p class="MsoNormal">text</p>""" diff -r f92823a66f18 -r da1cb2b12fe1 uilib.py --- a/uilib.py Tue Apr 07 17:08:53 2015 +0200 +++ b/uilib.py Fri Mar 27 15:29:34 2015 +0100 @@ -32,7 +32,7 @@ from logilab.common.date import ustrftime from logilab.common.deprecation import deprecated -from cubicweb.utils import JSString, json_dumps +from cubicweb.utils import js_dumps def rql_for_eid(eid): @@ -353,10 +353,7 @@ def __unicode__(self): args = [] for arg in self.args: - if isinstance(arg, JSString): - args.append(arg) - else: - args.append(json_dumps(arg)) + args.append(js_dumps(arg)) if self.parent: return u'%s(%s)' % (self.parent, ','.join(args)) return ','.join(args) @@ -378,6 +375,8 @@ 'cw.pouet(1,"2").pouet(null)' >>> str(js.cw.pouet(1, JSString("$")).pouet(None)) 'cw.pouet(1,$).pouet(null)' +>>> str(js.cw.pouet(1, {'callback': JSString("cw.cb")}).pouet(None)) +'cw.pouet(1,{callback: cw.cb}).pouet(null)' """ def domid(string): diff -r f92823a66f18 -r da1cb2b12fe1 web/test/unittest_web.py --- a/web/test/unittest_web.py Tue Apr 07 17:08:53 2015 +0200 +++ b/web/test/unittest_web.py Fri Mar 27 15:29:34 2015 +0100 @@ -50,7 +50,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])