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

[ExpressionLanguage] Fixed collisions of character operators with object properties #35707

Merged
merged 1 commit into from Feb 23, 2020

Conversation

Andrej-in-ua
Copy link
Contributor

@Andrej-in-ua Andrej-in-ua commented Feb 13, 2020

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

Expression foo.not in [bar] compiles to invalid php code:

$foo->not in[$bar]

Added check for absence of a dot before of the character operators.

PS. I apologize for not starting the issue before create PR. I considered this bug is minor, but obvious.

@nicolas-grekas
Copy link
Member

I suppose the same issue exists on 3.4? Can you please rebase+retarget the PR if confirmed?

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Feb 15, 2020
@Andrej-in-ua Andrej-in-ua force-pushed the fix-expression-lexer-operator-4.4 branch from 2b3d8e0 to 6ae75b6 Compare February 17, 2020 11:22
@Andrej-in-ua Andrej-in-ua changed the base branch from 4.4 to 3.4 February 17, 2020 11:22
@Andrej-in-ua Andrej-in-ua force-pushed the fix-expression-lexer-operator-4.4 branch from 6ae75b6 to cdfc4ea Compare February 17, 2020 11:55
@Andrej-in-ua
Copy link
Contributor Author

@nicolas-grekas Yes you are right, my mistake. I retarget the PR. Thanks!

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

See twigphp/Twig#3276 for a similar in Twig.

// - an operator that begins with a character must not be following after dot
// - an operator that ends with a character must be followed by a whitespace or a parenthesis
$regex[] =
(ctype_alpha($operator[$length - 1]) ? '(?<!\.)' : '')
Copy link
Member

Choose a reason for hiding this comment

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

should be $operator[0] as we want to test the first character as per the comment.

Copy link
Member

Choose a reason for hiding this comment

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

the test should be that a whitespace must be before the operator to cover other cases like foo|not in .... So the regex should be (?=[\s()]).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the test should be that a whitespace must be before the operator to cover other cases

Using whitespace incorrect work on case when operator in the start of expression - not foo .
Test https://github.com/symfony/symfony/pull/35707/files#diff-20d6647365cfcd9f6114d806f45a4771R184
I don't known Twig lexer, I will check this case.

Copy link
Member

Choose a reason for hiding this comment

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

Wrong copy/pasting on the regex, should be (?<=[\s(])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(?<=[\s(])not(?=[\s(]) not matched first not in case not foo.not or not bar.not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(?<=^|[\s(]) - works. I will fix it. Thank you.

@fabpot fabpot force-pushed the fix-expression-lexer-operator-4.4 branch from dd3eaf8 to 4b83ae7 Compare February 23, 2020 08:43
@fabpot
Copy link
Member

fabpot commented Feb 23, 2020

Thank you @Andrej-in-ua.

@fabpot fabpot merged commit 1676e3a into symfony:3.4 Feb 23, 2020
@Andrej-in-ua Andrej-in-ua deleted the fix-expression-lexer-operator-4.4 branch February 23, 2020 15:28
This was referenced Feb 29, 2020
@fabpot fabpot mentioned this pull request Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants