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

Skip to content

Commit b3f5501

Browse files
committed
Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Replace _s with ptr to avoid future confusion. Add also non regression tests.
1 parent 77821b6 commit b3f5501

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lib/test/string_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ def test_rfind(self):
262262
# issue 7458
263263
self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)
264264

265+
# issue #15534
266+
self.checkequal(0, '<......\u043c...', "rfind", "<")
267+
265268
def test_index(self):
266269
self.checkequal(0, 'abcdefghiabc', 'index', '')
267270
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
@@ -597,6 +600,8 @@ def test_replace(self):
597600
EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1)
598601
EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0)
599602
EQ("A----B----C----", "A.B.C.", "replace", ".", "----")
603+
# issue #15534
604+
EQ('...\u043c......&lt;', '...\u043c......<', "replace", "<", "&lt;")
600605

601606
EQ("Reykjavik", "Reykjavik", "replace", "q", "KK")
602607

@@ -1316,6 +1321,9 @@ def test_find_etc_raise_correct_error_messages(self):
13161321
self.assertRaisesRegex(TypeError, r'^endswith\(', s.endswith,
13171322
x, None, None, None)
13181323

1324+
# issue #15534
1325+
self.checkequal(10, "...\u043c......<", "find", "<")
1326+
13191327

13201328
class MixinStrUnicodeTest:
13211329
# Additional tests that only work with str and unicode.

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3.0 Beta 2?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15534: Fix the fast-search function for non-ASCII Unicode strings.
14+
1315
- Issue #15508: Fix the docstring for __import__ to have the proper default
1416
value of 0 for 'level' and to not mention negative levels since they are
1517
not supported.
@@ -83,7 +85,7 @@ Library
8385

8486
- Issue #15499: Launching a webbrowser in Unix used to sleep for a few
8587
seconds. Original patch by Anton Barkovsky.
86-
88+
8789
- Issue #15463: the faulthandler module truncates strings to 500 characters,
8890
instead of 100, to be able to display long file paths
8991

Objects/stringlib/fastsearch.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ STRINGLIB(fastsearch_memchr_1char)(const STRINGLIB_CHAR* s, Py_ssize_t n,
4848
} while (0)
4949

5050
if (mode == FAST_SEARCH) {
51-
const STRINGLIB_CHAR *_s = s;
51+
const STRINGLIB_CHAR *ptr = s;
5252
const STRINGLIB_CHAR *e = s + n;
53-
while (_s < e) {
54-
DO_MEMCHR(memchr, _s, needle, e - _s);
53+
while (ptr < e) {
54+
DO_MEMCHR(memchr, ptr, needle, e - ptr);
5555
if (found == NULL)
5656
return -1;
5757
if (sizeof(STRINGLIB_CHAR) == 1 || *found == ch)
58-
return (found - _s);
58+
return (found - s);
5959
/* False positive */
60-
_s = found + 1;
60+
ptr = found + 1;
6161
}
6262
return -1;
6363
}

0 commit comments

Comments
 (0)