[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5
victor.stinner
python-checkins at python.org
Tue Mar 1 15:31:20 EST 2016
https://hg.python.org/cpython/rev/aafbe5042024
changeset: 100380:aafbe5042024
parent: 100378:c092148a1b55
parent: 100379:27ba9ba5deb1
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Mar 01 21:30:50 2016 +0100
summary:
Merge 3.5
files:
Lib/test/test_unicode.py | 4 ++++
Misc/NEWS | 4 ++++
Objects/unicodeobject.c | 7 ++++---
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -347,6 +347,10 @@
"[a]")
self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': None})),
"[]")
+ self.assertEqual('axb'.translate(str.maketrans({'a': None, 'b': '123'})),
+ "x123")
+ self.assertEqual('axb'.translate(str.maketrans({'a': None, 'b': '\xe9'})),
+ "x\xe9")
# invalid Unicode characters
invalid_char = 0x10ffff+1
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
Core and Builtins
-----------------
+- Issue #26464: Fix str.translate() when string is ASCII and first replacements
+ removes character, but next replacement uses a non-ASCII character or a
+ string longer than 1 character. Regression introduced in Python 3.5.0.
+
- Issue #22836: Ensure exception reports from PyErr_Display() and
PyErr_WriteUnraisable() are sensible even when formatting them produces
secondary errors. This affects the reports produced by
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8783,7 +8783,8 @@
translated into writer, raise an exception and return -1 on error. */
static int
unicode_fast_translate(PyObject *input, PyObject *mapping,
- _PyUnicodeWriter *writer, int ignore)
+ _PyUnicodeWriter *writer, int ignore,
+ Py_ssize_t *input_pos)
{
Py_UCS1 ascii_table[128], ch, ch2;
Py_ssize_t len;
@@ -8830,6 +8831,7 @@
exit:
writer->pos = out - PyUnicode_1BYTE_DATA(writer->buffer);
+ *input_pos = in - PyUnicode_1BYTE_DATA(input);
return res;
}
@@ -8875,7 +8877,7 @@
ignore = (errors != NULL && strcmp(errors, "ignore") == 0);
- res = unicode_fast_translate(input, mapping, &writer, ignore);
+ res = unicode_fast_translate(input, mapping, &writer, ignore, &i);
if (res < 0) {
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
@@ -8883,7 +8885,6 @@
if (res == 1)
return _PyUnicodeWriter_Finish(&writer);
- i = writer.pos;
while (i<size) {
/* try to encode it */
int translate;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list