Skip to content

Commit dbefbc2

Browse files
[DI] align IniFileLoader to PHP bugfix #76965
1 parent 9d2e5ef commit dbefbc2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Loader/IniFileLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function supports($resource, $type = null)
7070
private function phpize($value)
7171
{
7272
// trim on the right as comments removal keep whitespaces
73-
$value = rtrim($value);
73+
if ($value !== $v = rtrim($value)) {
74+
$value = '""' === substr_replace($v, '', 1, -1) ? substr($v, 1, -1) : $v;
75+
}
7476
$lowercaseValue = strtolower($value);
7577

7678
switch (true) {

Tests/Fixtures/ini/types.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
constant = PHP_VERSION
1212
12 = 12
1313
12_string = '12'
14+
12_quoted_number = "12"
1415
12_comment = 12 ; comment
1516
12_string_comment = '12' ; comment
16-
12_string_comment_again = "12" ; comment
17+
12_quoted_number_comment = "12" ; comment
1718
-12 = -12
1819
0 = 0
1920
1 = 1

Tests/Loader/IniFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function testTypeConversionsWithNativePhp($key, $value, $supported)
5858
$this->markTestSkipped(sprintf('Converting the value "%s" to "%s" is not supported by the IniFileLoader.', $key, $value));
5959
}
6060

61-
$this->loader->load('types.ini');
6261
$expected = parse_ini_file(__DIR__.'/../Fixtures/ini/types.ini', true, INI_SCANNER_TYPED);
6362
$this->assertSame($value, $expected['parameters'][$key], '->load() converts values to PHP types');
6463
}
@@ -78,9 +77,10 @@ public function getTypeConversions()
7877
array('constant', PHP_VERSION, true),
7978
array('12', 12, true),
8079
array('12_string', '12', true),
80+
array('12_quoted_number', 12, false), // INI_SCANNER_RAW removes the double quotes
8181
array('12_comment', 12, true),
8282
array('12_string_comment', '12', true),
83-
array('12_string_comment_again', '12', true),
83+
array('12_quoted_number_comment', 12, false), // INI_SCANNER_RAW removes the double quotes
8484
array('-12', -12, true),
8585
array('1', 1, true),
8686
array('0', 0, true),

0 commit comments

Comments
 (0)