Repository navigation
Conversation
rfind searched back from end itself, so it found a match that ran past
end, rejected it, and returned -1 without trying earlier matches:
rfind("abcabc", "c", 0, 5) gave -1 instead of 2.
count with an empty substring returned end - start + 1 even when start
was past end, giving negative counts: count("abc", "", 5) gave -1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two index-bound cases where pystring and Python disagree:
str.rfind(sub, end), which can return a match that starts beforeendbut runs past it. That match was rejected and the function returned -1 without looking for an earlier one. It now searches back fromend - sub.size(), so the first hit always fits.end - start + 1went negative whenstart > endafter adjusting the indices. It now returns 0 there, like Python.I compared
find,rfind,count,startswith,endswithandslicewith Python 3 on 6,000 random strings with random (also negative and out-of-range) bounds:rfinddiffered in 39 cases andcountin 308 before this change, and none after.Tests: added cases to the
rfindandcount_python3tests; 4 checks fail before the change andmake testpasses after. No new compiler warnings.