Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| ->useAttributeAsKey('key') | ||
| ->example(array('foo' =>'"@bar"','pi' =>3.14)) | ||
| ->prototype('array') | ||
| ->normalizeKeys(false) |
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.
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.
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.
We mergeda 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 theUPGRADE-4.1.md file).
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.
For the record, asimilar PR has been rejected on the workflow component to keep the BC. But in the workflow there was an alternative way to configure things.
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.
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.
stof commentedApr 3, 2018
this is indeed a BC break technically, in case some people use dashes in their global names (although that would be weird, as they are not allowed in Twig identifiers) |
stof commentedApr 3, 2018
This PR breaks BC for no benefit IMO, as leaving dashes untouched will not help at all (they are forbidden) |
ogizanagi commentedApr 3, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@stof : The issue here actually isn't that the global var name is transformed (it's already configured with twig:globals:some-global:{ 'some-key': 'some-value' } will expose: "some-global" => array: ["some_key" =>"some-value"] hence, a global variable named (using |
lstrojny commentedApr 3, 2018
@stof what@ogizanagi is saying @ogizanagi choice of name for the global itself is there to verify that the current behavior (which enables dashes in global names already) stays as is. |
fabpot commentedApr 4, 2018
I haven't checked, but this should be on 2.7 or master. |
lstrojny commentedApr 4, 2018
@fabpot rebased against 2.7 |
chalasr commentedApr 4, 2018
should be on master to me as well, consistent with the decision made in#21718 |
nicolas-grekas commentedApr 4, 2018
Lets' go for master on my side also. |
stof commentedApr 4, 2018
hmm, the key normalization is indeed done before the |
| publicfunctiontestArrayKeysInGlobalsAreNotNormalized() | ||
| { | ||
| $input =array( | ||
| 'globals' =>array('some-global' =>array('some-key' =>'some-value')), |
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.
Can you avoid using a dash in the global name itself, to make the test less confusing ?
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.
@stof I consciously did that to ensure that the normalization is also not happening for the global names themselves
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 would split that into two tests and use a meaningful test name then to make the intention more clear.
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.
Split the test
lstrojny commentedApr 4, 2018
@nicolas-grekas@chalasr I disagree it should go to master only, as it’s clearly a bugfix. The referenced decision in#21718 looks quite different for me. While it’s technically the same issue ("normalization where normalization shouldn't happen") the context matters a lot and the context is very different. Prioritizing BC at all costs in the context of authentications makes a lot of sense to me and I feel it was the right call. In the context of template globals though, correctness should be prioritized over complete backwards compatibility. Adding it to the UPGRADING file makes a lot of sense. |
fabpot commentedApr 5, 2018
@lstrojny The problem is that we cannot afford to break some code out there in a patch release. Unfortunately, we've had several such cases in the past (and quite recently with the latest releases). The story is always the same: we find something that we want to fix in 2.7, which is a bug that also changes the current behavior in subtle ways, but we think that it's ok as nobody can rely on this bad behavior, and of course, some people are relying on the buggy behavior, they are upset, we are reverting, and I need to do another quick release (2.7, 2.8, 3.4, and 4.0 right now). Lot of time and frustration. So, I would advise to target master on this one. |
lstrojny commentedApr 19, 2018
Split the test and rebased against master. Ready to be merged from my POV |
fabpot commentedApr 20, 2018
Thank you@lstrojny. |
This PR was merged into the 4.1-dev branch.Discussion----------Do not normalize array keys in twig globals| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| BC breaks? | rather no| Tests pass? | yes| Fixed tickets | n.A.| License | MIT| Doc PR | n.A.We should leave array keys in twig globals untouched.Commits-------8c16727 Don’t normalize global values
We should leave array keys in twig globals untouched.