divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00019
[Merge] lp:~divmod-dev/divmod.org/nevow-json into lp:divmod.org
Jean-Paul Calderone has proposed merging lp:~divmod-dev/divmod.org/nevow-json into lp:divmod.org.
Requested reviews:
Divmod-dev (divmod-dev)
Related bugs:
Bug #805734 in nevow: "nevow.json serializes some line terminators such that Athena cannot deserialize them in the browser"
https://bugs.launchpad.net/nevow/+bug/805734
For more details, see:
https://code.launchpad.net/~divmod-dev/divmod.org/nevow-json/+merge/66843
I added U+2028 and U+2029 to nevow.json.serialize's special cased code points. It already handled \r and \n. I added a test for these four cases specifically, too.
--
https://code.launchpad.net/~divmod-dev/divmod.org/nevow-json/+merge/66843
Your team Divmod-dev is requested to review the proposed merge of lp:~divmod-dev/divmod.org/nevow-json into lp:divmod.org.
=== modified file 'Nevow/nevow/json.py'
--- Nevow/nevow/json.py 2008-05-22 18:46:50 +0000
+++ Nevow/nevow/json.py 2011-07-04 23:37:27 +0000
@@ -243,6 +243,8 @@
ord(u'\n'): ur'\n',
ord(u'\t'): ur'\t',
ord(u'\r'): ur'\r',
+ ord(u'\u2028'): u'\\u2028',
+ ord(u'\u2029'): u'\\u2029',
})
def stringEncode(s):
=== modified file 'Nevow/nevow/test/test_json.py'
--- Nevow/nevow/test/test_json.py 2010-07-12 19:00:11 +0000
+++ Nevow/nevow/test/test_json.py 2011-07-04 23:37:27 +0000
@@ -107,6 +107,24 @@
self.assertEquals(unstruct, struct, failMsg)
self.assert_(isinstance(unstruct, unicode), failMsg)
+
+ def test_lineTerminators(self):
+ """
+ When passed a unicode string containing a line terminator,
+ L{json.serialize} emits an escape sequence representing that character
+ (not a UTF-8 sequence directly representing that the line terminator
+ code point).
+
+ Literal line terminators are allowed in JSON, but some parsers do not
+ handle them properly.
+ """
+ # These are the four line terminators currently in Unicode.
+ self.assertEqual('"\\r"', json.serialize(u"\r"))
+ self.assertEqual('"\\n"', json.serialize(u"\n"))
+ self.assertEqual('"\\u2028"', json.serialize(u"\u2028"))
+ self.assertEqual('"\\u2029"', json.serialize(u"\u2029"))
+
+
def testScientificNotation(self):
self.assertEquals(json.parse('1e10'), 10**10)
self.assertEquals(json.parse('1e0'), 1)
Follow ups