]> granicus.if.org Git - python/commitdiff
Issue #5067: improve some json error messages.
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 28 Jun 2012 23:59:54 +0000 (01:59 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 28 Jun 2012 23:59:54 +0000 (01:59 +0200)
Patch by Serhiy Storchaka.

1  2 
Lib/json/decoder.py
Modules/_json.c

Simple merge
diff --cc Modules/_json.c
index 40c2ced5028f6702900419fd7d7e8161bea5a30e,2a71b9fda981ce19a7631468623806918ffce0db..fb8bd594e9cefc104de86af3b5248ecdd581c329
@@@ -645,8 -633,8 +645,8 @@@ _parse_object_unicode(PyScannerObject *
              PyObject *memokey;
  
              /* read key */
 -            if (str[idx] != '"') {
 +            if (PyUnicode_READ(kind, str, idx) != '"') {
-                 raise_errmsg("Expecting property name", pystr, idx);
+                 raise_errmsg("Expecting property name enclosed in double quotes", pystr, idx);
                  goto bail;
              }
              key = scanstring_unicode(pystr, idx + 1, strict, &next_idx);
              idx = next_idx;
  
              /* skip whitespace between key and : delimiter, read :, skip whitespace */
 -            while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
 -            if (idx > end_idx || str[idx] != ':') {
 +            while (idx <= end_idx && IS_WHITESPACE(PyUnicode_READ(kind, str, idx))) idx++;
 +            if (idx > end_idx || PyUnicode_READ(kind, str, idx) != ':') {
-                 raise_errmsg("Expecting : delimiter", pystr, idx);
+                 raise_errmsg("Expecting ':' delimiter", pystr, idx);
                  goto bail;
              }
              idx++;
  
              /* bail if the object is closed or we didn't get the , delimiter */
              if (idx > end_idx) break;
 -            if (str[idx] == '}') {
 +            if (PyUnicode_READ(kind, str, idx) == '}') {
                  break;
              }
 -            else if (str[idx] != ',') {
 +            else if (PyUnicode_READ(kind, str, idx) != ',') {
-                 raise_errmsg("Expecting , delimiter", pystr, idx);
+                 raise_errmsg("Expecting ',' delimiter", pystr, idx);
                  goto bail;
              }
              idx++;
@@@ -793,11 -773,11 +793,11 @@@ _parse_array_unicode(PyScannerObject *s
  
              /* bail if the array is closed or we didn't get the , delimiter */
              if (idx > end_idx) break;
 -            if (str[idx] == ']') {
 +            if (PyUnicode_READ(kind, str, idx) == ']') {
                  break;
              }
 -            else if (str[idx] != ',') {
 +            else if (PyUnicode_READ(kind, str, idx) != ',') {
-                 raise_errmsg("Expecting , delimiter", pystr, idx);
+                 raise_errmsg("Expecting ',' delimiter", pystr, idx);
                  goto bail;
              }
              idx++;