Skip to content

[Validator][Choice] Fix callback option if not array or iterable returned #58611

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

Closed

Conversation

symfonyaml
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58610
License MIT

Issue

When using the Choice validator callback option, and the callback method provided does not return an array or iterable, it causes a PHP error.
See all details and how to reproduce it in the issue #58610

Solution

In this PR

  • Add some checks if the callback method provided returns an array or iterable
  • Add tests for exception and iterable

@carsonbot carsonbot added this to the 5.4 milestone Oct 21, 2024
@symfonyaml symfonyaml changed the title [Validator] Fix choice callback option if not array or iterable returned [Validator][Choice] Fix callback option if not array or iterable returned Oct 21, 2024
@stof
Copy link
Member

stof commented Oct 21, 2024

should we mention the name of the callable in the error message, to make it easier to debug ?

@symfonyaml
Copy link
Contributor Author

@stof Thank you for your review. That's a good idea, I will add that the callable in the error message.

HypeMC and others added 23 commits October 21, 2024 16:39
Since symfony#54471, dumpFile will trigger a `fileperms(): stat failed`
error when writing to a filename that does not yet exist. This
was silenced from PHP's default handler with the `@` operator.

However, the error is still passed to any custom handler that the
application has registered, and can therefore cause exceptions or
spurious logging depending on the implementation of the handler.

The better solution, which is consistent with all other calls to
native functions in this class, would be to use `self::box` to
catch and ignore the potential error so that it never leaks
outside this class.
xabbuh and others added 16 commits October 21, 2024 16:39
This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

CS: clean some whitespaces/indentation

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix CS
| License       | MIT

Commits
-------

d0f63b8 CS: clean some whitespaces/indentation
The changes done in symfony#58453 were not enough. Since the session name is used
as the cookie name it must not be the empty string.
The test name argument is mandatory since PHPUnit 10.
The former test implementation relied on the order in which tests are
executed assuming that tests explicitly creating the schema were executed
first. This assumption leads to test failures on PHPUnit 10+ were tests
defined in parent classes are run first where they were run later with
PHPUnit 9.6.
Oracle converts all not quoted names to uppercase
@symfonyaml
Copy link
Contributor Author

I applied this from the doc
but still wrong rebase ....... I create another PR.

@symfonyaml symfonyaml closed this Oct 21, 2024
@symfonyaml symfonyaml deleted the fix-choice-validator-callback-iterable branch October 21, 2024 14:45
@symfonyaml
Copy link
Contributor Author

@stof new PR #58615 , sorry .....

@stof
Copy link
Member

stof commented Oct 21, 2024

@symfonyaml looks like you rebase on top of the latest 7.2 branch instead of the latest 5.4 branch (as your PR targets 5.4)

nicolas-grekas added a commit that referenced this pull request Oct 22, 2024
…rned (symfonyaml)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Validator] [Choice] Fix callback option if not array returned

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58610
| License       | MIT

### Issue
When using the Choice validator `callback` option, and the callback method provided does not return an array or iterable, it causes a PHP error.
See all details and how to reproduce it in the issue #58610

### Solution
In this PR
 - Add some checks if the callback method provided returns an array or iterable
 - Add tests for exception and iterable

________________
**NOTE** : This PR replaces [the old one](#58611) _(I messed up with the branch rebase)_

Commits
-------

02d2769 [Validator] [Choice] Fix callback option if not array returned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.