Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Allow "json:" env var processor to accept null value#26498
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedMar 12, 2018
There are reasons for the current restriction:
|
mcfedr commentedMar 12, 2018
I wondered if this might be what's happening. I have a case where in passing either an array or null. |
nicolas-grekas commentedMar 12, 2018
if you want to set |
javiereguiluz commentedMar 12, 2018
@nicolas-grekas but I think he's saying that an external piece of software generates this config that usually is a JSON-encoded array but it can be |
mcfedr commentedMar 12, 2018
Exactly, I need to accept either array or null. |
nicolas-grekas commentedMar 14, 2018
would you mind adding a test case please? |
05ec676 tofdee150Comparemcfedr commentedMar 15, 2018
Sure, also added some more general testing around EnvVarProcessor as there don't seem to exist any at the moment. |
| useSymfony\Component\DependencyInjection\EnvVarProcessor; | ||
| useSymfony\Component\DependencyInjection\Exception\LogicException; | ||
| class EnvVarProcessorTestextends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
would you mind opening a separate PR against branch 3.4 for this test class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok, I moved to#26542, but had to remove the case forjson:null because it will fail in 3.4, and i cannot add it here until that PR lands in master. I can probably make another PR later with more cases.
| if (!is_array($env)) { | ||
| if (null !==$env &&!is_array($env)) { | ||
| thrownewRuntimeException(sprintf('Invalid JSON env var "%s": array expected, %s given.',$name,gettype($env))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The error message should be updated:array expected ... ->array or null expected ...
d523a2c to98b1ae5Comparemcfedr commentedMar 19, 2018
Rebased on master to see if it would fix the tests, but now seems to fail on some other doctrine tests |
This PR was squashed before being merged into the 3.4 branch (closes#26542).Discussion----------[DI] Add tests for EnvVarProcessor| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | n/aAdd tests for the `EnvVarProcessor` as it doesn't have any at the moment.Originally from this PR against master,#26498Commits-------2992bb3 [DI] Add tests for EnvVarProcessor
nicolas-grekas commentedMar 19, 2018
@mcfedr you said had more tests in |
mcfedr commentedMar 19, 2018
nicolas-grekas commentedMar 19, 2018
Indeed. Merge done, rebase unlocked on your side. |
mcfedr commentedMar 19, 2018
Ok, rebased with extra test cases |
Amend EnvVarProcessorTest to include all possible json values
fabpot commentedMar 27, 2018
Thank you@mcfedr. |
…mcfedr)This PR was merged into the 4.1-dev branch.Discussion----------Allow "json:" env var processor to accept null value| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR | Currently no docs for this featureEdits the EnvVarProcessor so that it allows any type of variable in JSON encoded vars.Previously it was only possible to use `%env(json:ENV)%` for array types, but this seems to be an arbitrary restriction, when I could have any other data type in that JSON.Valid JSON that was previously rejected:- `1`- `null`- `"string"`Commits-------abc7480 Allow "json:" env var processor to parse null values
ro0NL commentedMar 27, 2018
@mcfedr anything to do for this test?https://github.com/symfony/symfony/pull/23888/files#diff-d81d0f25c32e251a89ce524b0495113dR74 |
mcfedr commentedMar 27, 2018
@ro0NL I don't see anything specific to this change, this PR makes it possible for the |
Edits the EnvVarProcessor so that it allows any type of variable in JSON encoded vars.
Previously it was only possible to use
%env(json:ENV)%for array types, but this seems to be an arbitrary restriction, when I could have any other data type in that JSON.Valid JSON that was previously rejected:
1null"string"