-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] fixed ini file values conversion #20232
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
ea41f76
to
db988f3
Compare
👍 It can be debatable to merge it in 2.7 or master ... but to me this is a bugfix, so it should stay in 2.7. |
👍 |
👍 for 2.7 also |
db988f3
to
ead4617
Compare
'-10100.1' => -10100.1, | ||
'-10,100.1' => '-10,100.1', | ||
); | ||
$this->assertEquals($expected, $this->container->getParameterBag()->all(), '->load() converts values to PHP types'); |
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.
AFAIK assertEquals doesn't ensure correct types, e.g. '1' == 1
. So the test is not really precise.
f77cdda
to
4110de6
Compare
@fabpot can you test with edit: also constants/nulls are affected |
@ro0NL Not sure I understand your concern. Can you be more precise? |
This breaks configuration like [parameters]
is_this_enabled = yes ; comment right? AFAIK this is not covered by Before edit: comments are just buggy with INI_SCANNER_RAW :) https://3v4l.org/7pV3u |
@fabpot perhaps more serious, no escaping is applied: https://3v4l.org/oGJqj |
@ro0NL is right, we need to polyfill |
@@ -40,6 +33,34 @@ public function testIniFileCanBeLoaded() | |||
} | |||
|
|||
/** | |||
* @requires PHP 5.3 |
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.
useless, as we cannot run on PHP < 5.3 anyway
@nicolas-grekas we basically already doing that with Imo a
would be sufficient. or simply patch the current ini loader on numerics, etc. |
4accc8f
to
8a3e741
Compare
("'" === $value[0] && "'" === $value[strlen($value) - 1]) || | ||
('"' === $value[0] && '"' === $value[strlen($value) - 1]) | ||
): | ||
// quoted string |
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.
Perhaps throw if 1 === strlen($value)
(invalid syntax)?
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 php.ini file would not be valid in that case.
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.
It was fatal before :/ https://3v4l.org/VgDvJ
With SCANNER_RAW it parses though.. but that doesnt mean it's valid, it's raw :)
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.
fixed
I've updated this PR to take into account how the scanner type convert values, and added some more tests. As for the failure on PHP 7.1, not sure what changed. Is it better now? |
8a3e741
to
5026d27
Compare
5026d27
to
824520d
Compare
I propose to merge it into master instead of 2.7 as it's more complex than anticipated. |
Using |
@nicolas-grekas Not really possible as our behavior is not exactly the same (we must be as close as possible to it but also be closed to what XmlUtils does to be consistent with the other formats). |
return true; | ||
case 'no' === $value || 'off' === $value || 'none' === $value: | ||
return false; | ||
case isset($value[0]) && ( |
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.
I propose this patch:
--- a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php
@@ -64,15 +64,16 @@ class IniFileLoader extends FileLoader
{
// trim on the right as a comment leaves the whitespaces in place
$value = rtrim($value);
+ $lowercaseValue = strtolower($value);
switch (true) {
case defined($value):
return constant($value);
- case 'yes' === $value || 'on' === $value:
+ case 'yes' === $lowercaseValue || 'on' === $lowercaseValue:
return true;
- case 'no' === $value || 'off' === $value || 'none' === $value:
+ case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue:
return false;
- case isset($value[0]) && (
+ case isset($value[1]) && (
("'" === $value[0] && "'" === $value[strlen($value) - 1]) ||
('"' === $value[0] && '"' === $value[strlen($value) - 1])
):
diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json
index 9c12d11..e24187f 100644
--- a/src/Symfony/Component/DependencyInjection/composer.json
+++ b/src/Symfony/Component/DependencyInjection/composer.json
@@ -20,7 +20,7 @@
},
"require-dev": {
"symfony/yaml": "~2.3.42|~2.7.14|~2.8.7",
- "symfony/config": "~2.2",
+ "symfony/config": "~2.7",
"symfony/expression-language": "~2.6"
},
"conflict": {
824520d
to
7e315ac
Compare
7e315ac
to
61b4c4a
Compare
Rebased on master |
61b4c4a
to
4ccfce6
Compare
… (fabpot) This PR was merged into the 3.2-dev branch. Discussion ---------- [DependencyInjection] fixed ini file values conversion | Q | A | | --- | --- | | Branch? | master | | Bug fix? | yes | | New feature? | no | | BC breaks? | no-ish | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | n/a | | License | MIT | | Doc PR | n/a | When using the ini format to load parameters in the Container, the parameter values were converted by PHP directly (`'true'` => `1` for instance). But when using the YAML or XML format, the conversions are much broader and more precise (`'true'` => `true` for instance). This PR fixed fixes this discrepancy by using the same rules as XML (we could use `INI_SCANNER_TYPED` for recent versions of PHP but the rules are not exactly the same, so I prefer consistency here). One might argue that this is a new feature and that this should be merged into master, which I can accept as well. In master, the `XmlUtils::phpize()` method should be deprecated and replaced by a more generic phpize class. ping @symfony/deciders Commits ------- 4ccfce6 [DependencyInjection] fixed ini file values conversion
…Cat) This PR was merged into the 4.4 branch. Discussion ---------- [Config] Remove obsolete warning about INI files Spotted thanks to #17232 (comment) Since symfony/symfony#20232 the claim that “you can only set parameters to string values” is not valid anymore. Commits ------- 7a67d8f Remove obsolete warning
When using the ini format to load parameters in the Container, the parameter values were converted by PHP directly (
'true'
=>1
for instance). But when using the YAML or XML format, the conversions are much broader and more precise ('true'
=>true
for instance). This PR fixed fixes this discrepancy by using the same rules as XML (we could useINI_SCANNER_TYPED
for recent versions of PHP but the rules are not exactly the same, so I prefer consistency here).One might argue that this is a new feature and that this should be merged into master, which I can accept as well. In master, the
XmlUtils::phpize()
method should be deprecated and replaced by a more generic phpize class.ping @symfony/deciders