Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2015-05-25.11:41:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432554087.61.0.0896292215981.issue24284@psf.upfronthosting.co.za>
In-reply-to
Content
The behavior of startswith in corner case is inconsistent between str and bytes in Python 3, str and unicode in Python 2, and between str in Python 2 and Python 3.

Python 3:
>>> ''.startswith('', 1, 0)
True
>>> b''.startswith(b'', 1, 0)
False

Python 2:
>>> ''.startswith('', 1, 0)
False
>>> u''.startswith(u'', 1, 0)
True

If define s1.startswith(s2, start, end) for non-negative indices and non-tuple s2 as an equivalent to the expression `start + len(s2) <= end and s2[start: start + len(s2)] == s2` or to `s1.find(s2, start, end) == start`, "".startswith("", 1, 0) should be False.

The same issue exists for endswith. See issue24243 for more detailed discussion.

Proposed patch fixes str.startswith and str.endswith.
History
Date User Action Args
2015-05-25 11:41:27serhiy.storchakasetrecipients: + serhiy.storchaka
2015-05-25 11:41:27serhiy.storchakasetmessageid: <1432554087.61.0.0896292215981.issue24284@psf.upfronthosting.co.za>
2015-05-25 11:41:27serhiy.storchakalinkissue24284 messages
2015-05-25 11:41:27serhiy.storchakacreate