-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Str::afterLast() #31085
Comments
Which, to me, would be correct. Explain your expectation. |
strpos 0: - My expectation is, that the last occurrence of "---" is at strpos 1-3. So the Result has to be "Foo". |
This does indeed look odd. I would expect This is only a problem when the search string is only one character and there is a sequence of the same character in the subject string of a length that is not a multiple of the search string's length. |
This works as expected. |
Definitely see the issue now upon further inspection. 🤷🏻♂️ |
@driesvints Could you please explain, why the last occurrence of "---" is not at strpos 1-3? |
Hmm, you're indeed correct. I misread this. Wondering what's causing this. |
I tried to explain the cause in my first post. The current implementation explodes the string using the search string as a delimiter. This works fine for almost all cases. It only breaks when the search string is a sequence of the same character and there is a sequence of that character of length greater than the search string and not a multiple of the length of the search string, because the string explodes on the first occurrence of the search string. For the example being used here, the search string If we want to fix this edge case, |
I tried |
I've sent in a fix for this. Thanks for reporting 👍 |
Description:
I think there is a bug in Str::afterLast().
Steps To Reproduce:
The statement
Str::afterLast('----Foo','---')
delivers "-Foo" instead of "Foo".The text was updated successfully, but these errors were encountered: