Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a465cb

Browse files
bpo-24214: Fixed the UTF-8 incremental decoder. (GH-12603)
The bug occurred when the encoded surrogate character is passedto the incremental decoder in two chunks.
1 parent38f4e46 commit7a465cb

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

‎Lib/test/test_codecs.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ def test_lone_surrogates(self):
406406
self.assertEqual(test_sequence.decode(self.encoding,"backslashreplace"),
407407
before+backslashreplace+after)
408408

409+
deftest_incremental_surrogatepass(self):
410+
# Test incremental decoder for surrogatepass handler:
411+
# see issue #24214
412+
data='\uD901'.encode(self.encoding,'surrogatepass')
413+
foriinrange(1,len(data)):
414+
dec=codecs.getincrementaldecoder(self.encoding)('surrogatepass')
415+
self.assertEqual(dec.decode(data[:i]),'')
416+
self.assertEqual(dec.decode(data[i:],True),'\uD901')
417+
409418

410419
classUTF32Test(ReadTest,unittest.TestCase):
411420
encoding="utf-32"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed support of the surrogatepass error handler in the UTF-8 incremental
2+
decoder.

‎Objects/unicodeobject.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,6 +4883,9 @@ PyUnicode_DecodeUTF8Stateful(const char *s,
48834883
case2:
48844884
case3:
48854885
case4:
4886+
if (s==end||consumed) {
4887+
gotoEnd;
4888+
}
48864889
errmsg="invalid continuation byte";
48874890
startinpos=s-starts;
48884891
endinpos=startinpos+ch-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp