Skip to content
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

[7.x] Make Str::endsWith return false if both haystack and needle are empty strings #33434

Merged
merged 1 commit into from
Jul 6, 2020

Conversation

vlakoff
Copy link
Contributor

@vlakoff vlakoff commented Jul 5, 2020

Doing some investigations after looking at this Stack Overflow question, this Laravel PR and this RFC for PHP 8, I noticed the following with current Laravel code:

Str::startsWith('haystack', ''); // false
Str::startsWith('', '');         // false

Str::endsWith('haystack', '');   // false
Str::endsWith('', '');           // true, should be false

Str::contains('haystack', '');   // false
Str::contains('', '');           // false

Hence this PR to make Str::endsWith more consistent, and to add tests for this case.

Also refs #2628.

On a related note: most other languages (Java, .NET, Python...), and even future PHP 8, return true when the needle is an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants