merge r66932 and add a few py3k only checks
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index f0bc245..4e88ba6 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -18,11 +18,15 @@
def linecol(doc, pos):
- lineno = doc.count('\n', 0, pos) + 1
+ if isinstance(doc, bytes):
+ newline = b'\n'
+ else:
+ newline = '\n'
+ lineno = doc.count(newline, 0, pos) + 1
if lineno == 1:
colno = pos
else:
- colno = pos - doc.rindex('\n', 0, pos)
+ colno = pos - doc.rindex(newline, 0, pos)
return lineno, colno
diff --git a/Lib/json/tests/test_scanstring.py b/Lib/json/tests/test_scanstring.py
index cd205a4..025d15d 100644
--- a/Lib/json/tests/test_scanstring.py
+++ b/Lib/json/tests/test_scanstring.py
@@ -2,6 +2,7 @@
import decimal
from unittest import TestCase
+import json
import json.decoder
class TestScanString(TestCase):
@@ -101,3 +102,9 @@
self.assertEquals(
scanstring('["Bad value", truth]', 2, None, True),
('Bad value', 12))
+
+ def test_issue3623(self):
+ self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1,
+ "xxx")
+ self.assertRaises(UnicodeDecodeError,
+ json.encoder.encode_basestring_ascii, b"xx\xff")