diff options
Diffstat (limited to 'Lib/test/test_json/test_decode.py')
-rw-r--r-- | Lib/test/test_json/test_decode.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index 05d07b7..35c02de 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -77,5 +77,19 @@ class TestDecode: with self.assertRaisesRegex(TypeError, msg): self.json.load(BytesIO(b'[1,2,3]')) + def test_string_with_utf8_bom(self): + # see #18958 + bom_json = "[1,2,3]".encode('utf-8-sig').decode('utf-8') + with self.assertRaises(ValueError) as cm: + self.loads(bom_json) + self.assertIn('BOM', str(cm.exception)) + with self.assertRaises(ValueError) as cm: + self.json.load(StringIO(bom_json)) + self.assertIn('BOM', str(cm.exception)) + # make sure that the BOM is not detected in the middle of a string + bom_in_str = '"{}"'.format(''.encode('utf-8-sig').decode('utf-8')) + self.assertEqual(self.loads(bom_in_str), '\ufeff') + self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff') + class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass |