Skip to content
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

Make escaping on ternary expressions more fine-grained #2934

Merged
merged 1 commit into from Apr 11, 2019

Conversation

Projects
None yet
4 participants
@fabpot
Copy link
Contributor

commented Apr 10, 2019

closes #2146
closes #449
closes #539
closes #1174
closes #1320
closes #1739
closes #1333

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from a71800c to b86c6de Apr 10, 2019

@fabpot fabpot changed the title [WIP] Make escaping on ternary expressions more fine-grained Make escaping on ternary expressions more fine-grained Apr 10, 2019

@fabpot

This comment has been minimized.

Copy link
Contributor Author

commented Apr 10, 2019

@stof @nicolas-grekas Could you review this PR please? It's an important one as it involves escaping and I don't want to introduce a security issue.

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from 7e6e0a6 to 71c36dc Apr 11, 2019

Show resolved Hide resolved src/Node/Expression/InlinePrint.php
Show resolved Hide resolved src/NodeVisitor/EscaperNodeVisitor.php Outdated
Show resolved Hide resolved src/NodeVisitor/EscaperNodeVisitor.php Outdated
@stof

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2019

The existing auto-escaping rule (requiring both sides to be safe for the ternary to be safe) still applies when the ternary is nested in a more complex expressions ((var ?? 'something')|nl2br for instance), right ?

@fabpot

This comment has been minimized.

Copy link
Contributor Author

commented Apr 11, 2019

@stof that's correct.

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from 71c36dc to 205b2c9 Apr 11, 2019

@stof

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2019

Then the doc needs to make this more clear IMO. The note you added may make people think this would not be the case anymore.

@stof

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2019

We have an optimization in NullCoalesceExpression to use ?? when we have a NameExpression as expr2. This change will kill that in print nodes as any NullCoalesceExpression would be turned into a normal ConditionalExpression (with the right test though, but not the optimization).

Should we unwrap things and wrap then in an InlinePrintNode all the time, or only when the safety rules would be different for both branches ? If rules are the same in both branches, applying the escaping as done today does not hurt, but let the ConditionalExpression optimize itself when possible.

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from 205b2c9 to ac8f367 Apr 11, 2019

@fabpot

This comment has been minimized.

Copy link
Contributor Author

commented Apr 11, 2019

@stof we now only unwrap when the safety is not the same on the two branches.

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from ac8f367 to 906672e Apr 11, 2019

@fabpot fabpot force-pushed the fabpot:ternary-escaping branch from 906672e to dfa9411 Apr 11, 2019

@stof

stof approved these changes Apr 11, 2019

@fabpot fabpot merged commit dfa9411 into twigphp:1.x Apr 11, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

fabpot added a commit that referenced this pull request Apr 11, 2019

feature #2934 Make escaping on ternary expressions more fine-grained …
…(fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

Make escaping on ternary expressions more fine-grained

closes #2146
closes #449
closes #539
closes #1174
closes #1320
closes #1739
closes #1333

Commits
-------

dfa9411 made escaping on ternary expressions more fine-grained

@fabpot fabpot deleted the fabpot:ternary-escaping branch Apr 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.