Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d04d847

Browse files
committed
Issue #28774: Fix start/end pos in unicode_encode_ucs1().
Fix error position of the unicode error in ASCII and Latin1 encoders when a string returned by the error handler contains multiple non-encodable characters (non-ASCII for the ASCII codec, characters out of the U+0000-U+00FF range for Latin1).
1 parent 726a57d commit d04d847

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ What's New in Python 3.7.0 alpha 1
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #28774: Fix error position of the unicode error in ASCII and Latin1
14+
encoders when a string returned by the error handler contains multiple
15+
non-encodable characters (non-ASCII for the ASCII codec, characters out
16+
of the U+0000-U+00FF range for Latin1).
17+
1318
- Issue #28731: Optimize _PyDict_NewPresized() to create correct size dict.
1419
Improve speed of dict literal with constant keys up to 30%.
1520

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,7 +6798,7 @@ unicode_encode_ucs1(PyObject *unicode,
67986798
goto onError;
67996799

68006800
/* subtract preallocated bytes */
6801-
writer.min_size -= 1;
6801+
writer.min_size -= newpos - collstart;
68026802

68036803
if (PyBytes_Check(rep)) {
68046804
/* Directly copy bytes result to output. */
@@ -6835,7 +6835,7 @@ unicode_encode_ucs1(PyObject *unicode,
68356835
ch = PyUnicode_READ_CHAR(rep, i);
68366836
if (ch >= limit) {
68376837
raise_encode_exception(&exc, encoding, unicode,
6838-
pos, pos+1, reason);
6838+
collstart, collend, reason);
68396839
goto onError;
68406840
}
68416841
*str = (char)ch;

0 commit comments

Comments
 (0)