|
30 | 30 | import unittest |
31 | 31 |
|
32 | 32 | from remoteobjects import fields, http |
| 33 | +from six import PY2 |
33 | 34 | from tests import test_dataobject |
34 | 35 | from tests import utils |
35 | 36 |
|
@@ -81,6 +82,40 @@ class BasicMost(self.cls): |
81 | 82 | # Bad characters are replaced with the unicode Replacement Character 0xFFFD. |
82 | 83 | self.assertEqual(b.value, u"image by \ufffdrew Example") |
83 | 84 | h.request.assert_called_once_with(**request) |
| 85 | + h.reset_mock() |
| 86 | + |
| 87 | + # since simplejson 3.3.0, lone surrogates are passed through |
| 88 | + # https://github.com/simplejson/simplejson/commit/35816bfe2d0ddeb5ddcc68239683cbb35b7e3ff2 |
| 89 | + content = """{"name": "lone surrogate \\ud800", "value": "\\udc00 lone surrogate"}""" |
| 90 | + h = utils.mock_http(request, content) |
| 91 | + b = BasicMost.get('http://example.com/ohhai', http=h) |
| 92 | + # Lone surrogates are passed through as lone surrogates in the python unicode value |
| 93 | + self.assertEqual(b.name, u"lone surrogate \ud800") |
| 94 | + self.assertEqual(b.value, u"\udc00 lone surrogate") |
| 95 | + h.request.assert_called_once_with(**request) |
| 96 | + |
| 97 | + content = u"""{"name": "100 \u20AC", "value": "13000 \u00A5"}""".encode('utf-8') |
| 98 | + h = utils.mock_http(request, content) |
| 99 | + b = BasicMost.get('http://example.com/ohhai', http=h) |
| 100 | + # JSON containing non-ascii UTF-8 should be decoded to unicode strings |
| 101 | + self.assertEqual(b.name, u"100 \u20AC") |
| 102 | + self.assertEqual(b.value, u"13000 \u00A5") |
| 103 | + h.request.assert_called_once_with(**request) |
| 104 | + |
| 105 | + content = b"""{"name": "lone surrogate \xed\xa0\x80", "value": "\xed\xb0\x80 lone surrogate"}""" |
| 106 | + h = utils.mock_http(request, content) |
| 107 | + b = BasicMost.get('http://example.com/ohhai', http=h) |
| 108 | + # Lone surrogates are passed through as lone surrogates in the python unicode value |
| 109 | + if PY2: |
| 110 | + # in python2, our JSONDecoder does not detect naked lone surrogates |
| 111 | + self.assertEqual(b.name, u"lone surrogate \ud800") |
| 112 | + self.assertEqual(b.value, u"\udc00 lone surrogate") |
| 113 | + else: |
| 114 | + # in python3, bytes.decode replaces lone surrogates with replacement char |
| 115 | + self.assertEqual(b.name, u"lone surrogate \ufffd\ufffd\ufffd") |
| 116 | + self.assertEqual(b.value, u"\ufffd\ufffd\ufffd lone surrogate") |
| 117 | + |
| 118 | + h.request.assert_called_once_with(**request) |
84 | 119 |
|
85 | 120 | def test_post(self): |
86 | 121 |
|
|
0 commit comments