8000 Do not normalize array keys in twig globals by lstrojny · Pull Request #26770 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Do not normalize array keys in twig globals #26770

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

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private function addGlobalsSection(ArrayNodeDefinition $rootNode)
->useAttributeAsKey('key')
->example(array('foo' => '"@bar"', 'pi' => 3.14))
->prototype('array')
->normalizeKeys(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have the same issue in 2.7 as well? I'm wondering if it would not be "safer" to do this in master instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We merged a similar fix as an assumed BC break on master only. This one may have worse impacts. I don't think it is worth breaking existing apps relying on this behavior, so I'd do it on master only (and mention it in the UPGRADE-4.1.md file).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, a similar PR has been rejected on the workflow component to keep the BC. But in the workflow there was an alternative way to configure things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, one person’s bugfix is another person's BC break. Relying (and keeping) a behavior where the keys of an array magically change doesn't sound like a good idea to me though.

->beforeNormalization()
->ifTrue(function ($v) { return is_string($v) && 0 === strpos($v, '@'); })
->then(function ($v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ public function testGetStrictVariablesDefaultFalse()

$this->assertFalse($config['strict_variables']);
}

public function testGlobalsAreNotNormalized()
{
$input = array(
'globals' => array('some-global' => true),
);

$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array($input));

$this->assertSame(array('some-global' => array('value' => true)), $config['globals']);
}

public function testArrayKeysInGlobalsAreNotNormalized()
{
$input = array(
'globals' => array('global' => array('some-key' => 'some-value')),
);

$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array($input));

$this->assertSame(array('global' => array('value' => array('some-key' => 'some-value'))), $config['globals']);
}
}
0