Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
fabpot merged 1 commit intosymfony:masterfromlstrojny:dev/no-twig-global-normalization
Apr 20, 2018
Merged

Do not normalize array keys in twig globals#26770

fabpot merged 1 commit intosymfony:masterfromlstrojny:dev/no-twig-global-normalization
Apr 20, 2018

Conversation

@lstrojny
Copy link
Contributor

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?rather no
Tests pass?yes
Fixed ticketsn.A.
LicenseMIT
Doc PRn.A.

We should leave array keys in twig globals untouched.

ajb-in reacted with thumbs up emoji
@lstrojnylstrojny changed the base branch frommaster to3.4April 3, 2018 12:54
->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 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).

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, 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.

Copy link
ContributorAuthor

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
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor

ogizanagi commentedApr 3, 2018
edited
Loading

@stof : The issue here actually isn't that the global var name is transformed (it's already configured with->normalizeKeys(false)), but that an array registered as a global will see its keys transformed while those are perfectly fine. I.e:

twig:globals:some-global:{ 'some-key': 'some-value' }

will expose:

"some-global" => array: ["some_key" =>"some-value"]

hence, a global variable namedsome-global (you'll get some troubles accessing it indeed, but still doable using_context['some-global'] despite clearly not recommended) but with transformed array keys. Dashes in array keys aren't forbidden.

(usingsome-global as name for the global var in the test case is misleading regarding this)

@lstrojny
Copy link
ContributorAuthor

@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
Copy link
Member

I haven't checked, but this should be on 2.7 or master.

@lstrojnylstrojny changed the base branch from3.4 to2.7April 4, 2018 12:19
@lstrojny
Copy link
ContributorAuthor

@fabpot rebased against 2.7

@chalasr
Copy link
Member

should be on master to me as well, consistent with the decision made in#21718

@nicolas-grekas
Copy link
Member

Lets' go for master on my side also.
@lstrojny while rebasing, could you please add a note in the UPGRADING file about it?

@nicolas-grekasnicolas-grekas added this to the4.1 milestoneApr 4, 2018
@stof
Copy link
Member

stof commentedApr 4, 2018

hmm, the key normalization is indeed done before thebeforeNormalization callbacks, so the value is not yet in thevalue key of the array node (and so gets normalized)

publicfunctiontestArrayKeysInGlobalsAreNotNormalized()
{
$input =array(
'globals' =>array('some-global' =>array('some-key' =>'some-value')),
Copy link
Member

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 ?

ogizanagi and yceruto reacted with thumbs up emoji
Copy link
ContributorAuthor

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

Copy link
Member

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.

ogizanagi reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Split the test

@lstrojny
Copy link
ContributorAuthor

@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
Copy link
Member

@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.

@lstrojnylstrojny changed the base branch from2.7 tomasterApril 19, 2018 20:16
@lstrojny
Copy link
ContributorAuthor

Split the test and rebased against master. Ready to be merged from my POV

@fabpot
Copy link
Member

Thank you@lstrojny.

@fabpotfabpot merged commit8c16727 intosymfony:masterApr 20, 2018
fabpot added a commit that referenced this pull requestApr 20, 2018
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
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lyrixxlyrixxlyrixx left review comments

@stofstofstof left review comments

@xabbuhxabbuhxabbuh left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@ogizanagiogizanagiogizanagi left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

9 participants

@lstrojny@stof@ogizanagi@fabpot@chalasr@nicolas-grekas@lyrixx@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp