-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
OptionsResolver error message with string[] as allowedTypes #30432
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
Comments
Good catch, would you like to send a PR? |
@xabbuh I took a look at OptionsResolver component. Can you or someone else confirm how an error message should look like? For instance, the current implementation implies that this code (new OptionsResolver())
->setDefined('foo');
->setAllowedTypes('foo', 'int[][]');
->resolve([
'foo' => [
[1, true, 'str', [2, 3]],
],
]); will throw an exception with message |
For the example from the PR description the correct error message IMO indeed should be:
|
I got it. Confirm case when allowed types consist multidimensional array notation (e.g.
|
I would have expected an error message containing all invalid types:
|
Hm, seems like it requires a huge effort. But I will see what I can do with it. |
Thanks! |
…te (dimabory) This PR was merged into the 3.4 branch. Discussion ---------- [OptionsResolver] Fix an error message to be more accurate | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30432 | License | MIT | Doc PR | See #30432 for more details: > **Symfony version(s) affected**: 3.4, maybe other versions too (not tested) > > **Description** > Error message when allowedTypes is an array contains `[]` but should not: > `The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer[]".` > It should be: > `The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer".` > > **How to reproduce** > > ``` > $resolver = (new OptionsResolver()) > ->setDefault('testme', []) > ->setAllowedTypes('testme', ['string[]']) > ->resolve(['testme' => ['test', 12]]); > ``` In addition I changed an error message to be more accurate if provided more than one incorrect value: > [...] is expected to be of type "integer[][]", but is of type "integer|boolean|string". Commits ------- 7fa2fc2 #30432 fix an error message
* 3.4: #30432 fix an error message fix paths to detect code owners [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 Remove unused local variables in tests Make sure to collect child forms created on *_SET_DATA events do not render errors for checkboxes twice
* 4.3: [OptionsResolve] Revert change in tests for a not-merged change in code [HttpClient] fix handling of 3xx with no Location header - ignore Content-Length when no body is expected [Workflow] Made the configuration more robust for the 'property' key [Security/Core] make NativePasswordEncoder use sodium to validate passwords when possible #30432 fix an error message fix paths to detect code owners [HttpClient] ignore the body of responses to HEAD requests [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 [SecurityBundle] Fix wrong assertion Remove unused local variables in tests [Yaml][Parser] Remove the getLastLineNumberBeforeDeprecation() internal unused method Make sure to collect child forms created on *_SET_DATA events [WebProfilerBundle] Improve display in Email panel for dark theme do not render errors for checkboxes twice
* 4.4: [OptionsResolve] Revert change in tests for a not-merged change in code [HttpClient] fix handling of 3xx with no Location header - ignore Content-Length when no body is expected [Workflow] Made the configuration more robust for the 'property' key [Security/Core] make NativePasswordEncoder use sodium to validate passwords when possible [FrameworkBundle] make SodiumVault report bad decryption key accurately cs fix [Security] Allow to set a fixed algorithm [Security/Core] make encodedLength computation more generic [Security/Core] add fast path when encoded password cannot match anything #30432 fix an error message fix paths to detect code owners [HttpClient] ignore the body of responses to HEAD requests [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 [SecurityBundle] Fix wrong assertion Remove unused local variables in tests [Yaml][Parser] Remove the getLastLineNumberBeforeDeprecation() internal unused method Make sure to collect child forms created on *_SET_DATA events [WebProfilerBundle] Improve display in Email panel for dark theme do not render errors for checkboxes twice
* 4.4: [OptionsResolve] Revert change in tests for a not-merged change in code [HttpClient] fix handling of 3xx with no Location header - ignore Content-Length when no body is expected [Workflow] Made the configuration more robust for the 'property' key [Security/Core] make NativePasswordEncoder use sodium to validate passwords when possible [FrameworkBundle] make SodiumVault report bad decryption key accurately cs fix [Security] Allow to set a fixed algorithm [Security/Core] make encodedLength computation more generic [Security/Core] add fast path when encoded password cannot match anything symfony#30432 fix an error message fix paths to detect code owners [HttpClient] ignore the body of responses to HEAD requests [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 [SecurityBundle] Fix wrong assertion Remove unused local variables in tests [Yaml][Parser] Remove the getLastLineNumberBeforeDeprecation() internal unused method Make sure to collect child forms created on *_SET_DATA events [WebProfilerBundle] Improve display in Email panel for dark theme do not render errors for checkboxes twice
Symfony version(s) affected: 3.4, maybe other versions too (not tested)
Description
Error message when allowedTypes is an array contains
[]
but should not:The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer[]".
It should be:
The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer".
How to reproduce
The text was updated successfully, but these errors were encountered: