-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There are reasons for the current restriction:
|
I wondered if this might be what's happening. I have a case where in passing either an array or null. |
if you want to set |
@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 |
Exactly, I need to accept either array or null. |
would you mind adding a test case please? |
05ec676
to
fdee150
Compare
Sure, also added some more general testing around EnvVarProcessor as there don't seem to exist any at the moment. |
use Symfony\Component\DependencyInjection\EnvVarProcessor; | ||
use Symfony\Component\DependencyInjection\Exception\LogicException; | ||
|
||
class EnvVarProcessorTest extends 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 for json: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.
@@ -129,7 +129,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) | |||
throw new RuntimeException(sprintf('Invalid JSON in env var "%s": '.json_last_error_msg(), $name)); | |||
} | |||
|
|||
if (!is_array($env)) { | |||
if (null !== $env && !is_array($env)) { | |||
throw new RuntimeException(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
to
98b1ae5
Compare
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/a Add tests for the `EnvVarProcessor` as it doesn't have any at the moment. Originally from this PR against master, #26498 Commits ------- 2992bb3 [DI] Add tests for EnvVarProcessor
@mcfedr you said had more tests in |
Indeed. Merge done, rebase unlocked on your side. |
Ok, rebased with extra test cases |
Amend EnvVarProcessorTest to include all possible json values
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 feature 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: - `1` - `null` - `"string"` Commits ------- abc7480 Allow "json:" env var processor to parse null values
@mcfedr anything to do for this test? https://github.com/symfony/symfony/pull/23888/files#diff-d81d0f25c32e251a89ce524b0495113dR74 |
@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:
1
null
"string"