(self)
| 170 | self.assertIn('Unterminated string', str(cm.exception)) |
| 171 | |
| 172 | def test_surrogates(self): |
| 173 | scanstring = json.decoder.scanstring |
| 174 | |
| 175 | def assertScan(given, expect, test_utf8=True): |
| 176 | givens = [given] |
| 177 | if not PY3 and test_utf8: |
| 178 | givens.append(given.encode('utf8')) |
| 179 | for given in givens: |
| 180 | (res, count) = scanstring(given, 1, None, True) |
| 181 | self.assertEqual(len(given), count) |
| 182 | self.assertEqual(res, expect) |
| 183 | |
| 184 | assertScan( |
| 185 | u'"z\\ud834\\u0079x"', |
| 186 | u'z\ud834yx') |
| 187 | assertScan( |
| 188 | u'"z\\ud834\\udd20x"', |
| 189 | u'z\U0001d120x') |
| 190 | assertScan( |
| 191 | u'"z\\ud834\\ud834\\udd20x"', |
| 192 | u'z\ud834\U0001d120x') |
| 193 | assertScan( |
| 194 | u'"z\\ud834x"', |
| 195 | u'z\ud834x') |
| 196 | assertScan( |
| 197 | u'"z\\udd20x"', |
| 198 | u'z\udd20x') |
| 199 | assertScan( |
| 200 | u'"z\ud834x"', |
| 201 | u'z\ud834x') |
| 202 | # It may look strange to join strings together, but Python is drunk. |
| 203 | # https://gist.github.com/etrepum/5538443 |
| 204 | assertScan( |
| 205 | u'"z\\ud834\udd20x12345"', |
| 206 | u''.join([u'z\ud834', u'\udd20x12345'])) |
| 207 | assertScan( |
| 208 | u'"z\ud834\\udd20x"', |
| 209 | u''.join([u'z\ud834', u'\udd20x'])) |
| 210 | # these have different behavior given UTF8 input, because the surrogate |
| 211 | # pair may be joined (in maxunicode > 65535 builds) |
| 212 | assertScan( |
| 213 | u''.join([u'"z\ud834', u'\udd20x"']), |
| 214 | u''.join([u'z\ud834', u'\udd20x']), |
| 215 | test_utf8=False) |
| 216 | |
| 217 | self.assertRaises(ValueError, |
| 218 | scanstring, u'"z\\ud83x"', 1, None, True) |
| 219 | self.assertRaises(ValueError, |
| 220 | scanstring, u'"z\\ud834\\udd2x"', 1, None, True) |
| 221 | |
| 222 | def test_escape_error_parity(self): |
| 223 | # Regression: the C scanstring bounds check was `end >= len` / the |
nothing calls this directly
no outgoing calls
no test coverage detected