[Python-checkins] r66932 - in python/trunk: Lib/json/tests/test_scanstring.py Modules/_json.c

benjamin.peterson python-checkins at python.org
Thu Oct 16 23:09:28 CEST 2008


Author: benjamin.peterson
Date: Thu Oct 16 23:09:28 2008
New Revision: 66932

Log:
check for error conditions in _json #3623

Modified:
   python/trunk/Lib/json/tests/test_scanstring.py
   python/trunk/Modules/_json.c

Modified: python/trunk/Lib/json/tests/test_scanstring.py
==============================================================================
--- python/trunk/Lib/json/tests/test_scanstring.py	(original)
+++ python/trunk/Lib/json/tests/test_scanstring.py	Thu Oct 16 23:09:28 2008
@@ -2,6 +2,7 @@
 import decimal
 from unittest import TestCase
 
+import json
 import json.decoder
 
 class TestScanString(TestCase):
@@ -100,3 +101,9 @@
         self.assertEquals(
             scanstring('["Bad value", truth]', 2, None, True),
             (u'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")

Modified: python/trunk/Modules/_json.c
==============================================================================
--- python/trunk/Modules/_json.c	(original)
+++ python/trunk/Modules/_json.c	Thu Oct 16 23:09:28 2008
@@ -179,11 +179,13 @@
         errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
         if (errmsg_fn == NULL)
             return;
-        Py_XDECREF(decoder);
+        Py_DECREF(decoder);
     }
     pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
-    PyErr_SetObject(PyExc_ValueError, pymsg);
-    Py_DECREF(pymsg);
+    if (pymsg) {
+        PyErr_SetObject(PyExc_ValueError, pymsg);
+        Py_DECREF(pymsg);
+    }
 /*
 
 def linecol(doc, pos):


More information about the Python-checkins mailing list