Thanks to visit codestin.com
Credit goes to github.com

Skip to content

IniFileLoader throws when parsing arrays #47357

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

Closed
lpd-au opened this issue Aug 22, 2022 · 0 comments · Fixed by #47367
Closed

IniFileLoader throws when parsing arrays #47357

lpd-au opened this issue Aug 22, 2022 · 0 comments · Fixed by #47367

Comments

@lpd-au
Copy link

lpd-au commented Aug 22, 2022

Symfony version(s) affected

3.2.0-current

Description

Since #20232, IniFileLoader no longer works correctly with ini files containing arrays:

Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\DependencyInjection\Loader\IniFileLoader::phpize() must be of the type string, array given, called in vendor/symfony/dependency-injection/Loader/IniFileLoader.php on line 44 and defined in vendor/symfony/dependency-injection/Loader/IniFileLoader.php on line 72

Call Stack:
1. {main}()
2. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->load()
3. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->parseImports() vendor/symfony/dependency-injection/Loader/XmlFileLoader.php:59
4. Symfony\Component\DependencyInjection\Loader\FileLoader->import() vendor/symfony/dependency-injection/Loader/XmlFileLoader.php:111
5. Symfony\Component\Config\Loader\FileLoader->import() vendor/symfony/dependency-injection/Loader/FileLoader.php:66
6. Symfony\Component\Config\Loader\FileLoader->doImport() vendor/symfony/config/Loader/FileLoader.php:104
7. Symfony\Component\DependencyInjection\Loader\IniFileLoader->load() vendor/symfony/config/Loader/FileLoader.php:165
8. Symfony\Component\DependencyInjection\Loader\IniFileLoader->phpize() vendor/symfony/dependency-injection/Loader/IniFileLoader.php:44

Previously, per the default behaviour of INI_SCANNER_NORMAL, the loader would always return values as string|string[]. There were some possible value substitutions, eg "true" became "1", however the deepest nested values were always a string.

The linked PR added intermediate parsing to convert these values to other scalar types, but incorrectly assumes the only possible input type is string. (Since version 4.4, this is by typehinting the private method's parameter, and before that by immediately calling \rtrim on the value.) This conversion isn't mentioned at all in the upgrading notes and there's still a caution in the docs suggesting other types aren't supported.

How to reproduce

Load a config file such as:

[parameters]

this.works = true
these.work[] = false
these.fail[] = true

Expected values:

[
    "this.works" => true,
    "these.work" => [
        false
    ],
    "these.fail" => [
        true
    ]
]

Actual behaviour: TypeError thrown

Possible Solution

IniFileLoader::load should call \is_array on each parameter value, and when true call IniFileLoader::phpize for each array element instead of passing the entire array only once.

Additional Context

No response

@lpd-au lpd-au added the Bug label Aug 22, 2022
@fabpot fabpot closed this as completed Aug 26, 2022
fabpot added a commit that referenced this issue Aug 26, 2022
This PR was submitted for the 4.4 branch but it was merged into the 6.2 branch instead.

Discussion
----------

[DependencyInjection] Handle INI arrays

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #47357
| License       | MIT
| Doc PR        | N/A

Commits
-------

f90525c Handle INI arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants