[Python-checkins] r72236 - python/branches/pep-0383/Python/codecs.c

martin.v.loewis python-checkins at python.org
Sun May 3 20:30:40 CEST 2009


Author: martin.v.loewis
Date: Sun May  3 20:30:39 2009
New Revision: 72236

Log:
Refuse to escape ASCII bytes.


Modified:
   python/branches/pep-0383/Python/codecs.c

Modified: python/branches/pep-0383/Python/codecs.c
==============================================================================
--- python/branches/pep-0383/Python/codecs.c	(original)
+++ python/branches/pep-0383/Python/codecs.c	Sun May  3 20:30:39 2009
@@ -880,9 +880,17 @@
 	    return NULL;
 	}
 	while (consumed < 4 && consumed < end-start) {
+	    /* Refuse to escape ASCII bytes. */
+	    if (p[start+consumed] < 128)
+		break;
 	    ch[consumed] = 0xdc00 + p[start+consumed];
 	    consumed++;
 	}
+	if (!consumed) {
+	    /* codec complained about ASCII byte. */
+	    PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
+	    return NULL;
+	}	    
 	Py_DECREF(object);
 	return Py_BuildValue("(u#n)", ch, consumed, start+consumed);
     }


More information about the Python-checkins mailing list