mirror of
https://github.com/ultrajson/ultrajson.git
synced 2024-11-24 01:04:19 +01:00
Added support for encoding and escaping NULL (U+0000) as \\u0000
This commit is contained in:
parent
408e38cd8f
commit
3ecf8e9b0b
@ -456,6 +456,21 @@ class UltraJSONTests(TestCase):
|
||||
except OverflowError:
|
||||
pass
|
||||
|
||||
def test_encodeNullCharacter(self):
|
||||
input = "31337 \x00 1337"
|
||||
output = ujson.encode(input)
|
||||
|
||||
self.assertEquals(input, json.loads(output))
|
||||
self.assertEquals(output, json.dumps(input))
|
||||
self.assertEquals(input, ujson.decode(output))
|
||||
self.assertEquals('" \\u0000\\r\\n "', ujson.dumps(u" \u0000\r\n "))
|
||||
pass
|
||||
|
||||
def test_decodeNullCharacter(self):
|
||||
input = "\"31337 \\u0000 31337\""
|
||||
self.assertEquals(ujson.decode(input), json.loads(input))
|
||||
|
||||
|
||||
def test_encodeListLongConversion(self):
|
||||
input = [9223372036854775807, 9223372036854775807, 9223372036854775807, 9223372036854775807, 9223372036854775807, 9223372036854775807 ]
|
||||
output = ujson.encode(input)
|
||||
|
@ -1 +1 @@
|
||||
#define UJSON_VERSION "1.12"
|
||||
#define UJSON_VERSION "1.14"
|
||||
|
@ -134,8 +134,21 @@ int Buffer_EscapeStringUnvalidated (JSOBJ obj, JSONObjectEncoder *enc, const cha
|
||||
switch (*io)
|
||||
{
|
||||
case 0x00:
|
||||
enc->offset += (of - enc->offset);
|
||||
return TRUE;
|
||||
if (io < end)
|
||||
{
|
||||
*(of++) = '\\';
|
||||
*(of++) = 'u';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
enc->offset += (of - enc->offset);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case '\"': (*of++) = '\\'; (*of++) = '\"'; break;
|
||||
case '\\': (*of++) = '\\'; (*of++) = '\\'; break;
|
||||
@ -213,8 +226,22 @@ int Buffer_EscapeStringValidated (JSOBJ obj, JSONObjectEncoder *enc, const char
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
enc->offset += (of - enc->offset);
|
||||
return TRUE;
|
||||
if (io < end)
|
||||
{
|
||||
*(of++) = '\\';
|
||||
*(of++) = 'u';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
*(of++) = '0';
|
||||
io ++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
enc->offset += (of - enc->offset);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
|
Loading…
Reference in New Issue
Block a user