-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Fix Notice when argument is empty string #39244
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
An empty string might not be valid input, but we must not trigger a notice in that case, imho. Thank you very much for the PR. Can you provide a test for this change, please? |
b9f26f8
to
e9620ad
Compare
@derrabus Thank you for reviewing. I added tests, but now |
You can safely ignore fabbot here. |
I'd personally prefer adding the empty string to the |
@nicolas-grekas I also like the solution with Tested now with 4.4, seems that issue exists:
And PropertyAccesor have same behavior:
|
@nicolas-grekas Should i open another PR with fix for 4.4? |
I think the test cases are enough to remind about this.
yes please! |
e9620ad
to
88c2b9b
Compare
@nicolas-grekas added to For 4.4: #39270 |
…man) This PR was merged into the 4.4 branch. Discussion ---------- [Inflector] Fix Notice when argument is empty string | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | License | MIT Fixing issue when we call `Inflector` with empty string: ``` \Symfony\Component\Inflector\Inflector::singularize(''); ``` ``` Notice: Uninitialized string offset: 0 in src/Symfony/Component/Inflector/Inflector.php on line 363 PHP Notice: Uninitialized string offset: 0 in src/Symfony/Component/Inflector/Inflector.php on line 363 ... Notice: Uninitialized string offset: 0 in src/Symfony/Component/Inflector/Inflector.php on line 363 PHP Notice: Uninitialized string offset: 0 in src/Symfony/Component/Inflector/Inflector.php on line 363 ``` Fix for 5.1 #39244 Commits ------- 2dfe342 [Inflector] Fix Notice when argument is empty string
Good catch, thanks @moldman. |
PHP Notice is generated when we pass empty string to
singularize
orpluralize
method.Background:
When
\Symfony\Component\PropertyAccess\PropertyAccessorInterface::setValue
is used with_
property, then it calls \Symfony\Component\String\Inflector\EnglishInflector::singularize with empty string.P.S.
Another solution is to include empty string in \Symfony\Component\String\Inflector\EnglishInflector::$uninflected
If this PR is not relevant please close and sorry for inconvenience.