Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ExpressionLanguage] Fix matches when the regexp is not valid #45875

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
Mar 30, 2022

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Mar 28, 2022

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

@fabpot fabpot force-pushed the expression-language-matches-fix branch from 22f81a7 to b2da2f8 Compare March 30, 2022 10:36
@fabpot fabpot force-pushed the expression-language-matches-fix branch from b2da2f8 to f09da16 Compare March 30, 2022 11:46
@fabpot fabpot merged commit 7dc98de into symfony:4.4 Mar 30, 2022
@fabpot fabpot deleted the expression-language-matches-fix branch March 30, 2022 14:40
This was referenced Apr 2, 2022
fabpot added a commit that referenced this pull request Apr 3, 2022
…xpression (ausi)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[ExpressionLanguage] Fix matching null against a regular expression

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45926
| License       | MIT
| Doc PR        | -

As discussed in #45926 (comment)

The bug was introduced by #45875

Commits
-------

3326da0 [ExpressionLanguage] Fix matching null against a regular expression
fabpot added a commit that referenced this pull request Oct 6, 2024
…g used as regexp (ivantsepp)

This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

[ExpressionLanguage] Fix matches to handle booleans being used as regexp

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | n/a
| License       | MIT

I'm marking this as a bug fix but this could be seen as a "new feature" as existing `matches` syntax functionality works just fine.

I wanted to build on top of the work done at #45875. This handles invalid regular expressions and also does an extra check inside the `compile` method. It checks the right hand side for a `ConstantNode` and validates that it's a valid regexp. The idea is that we can go **even further** and check for `BinaryNode` because in most cases, this is an invalid regexp since a boolean usually returned. The exception is `~` which is for string concatenation since that could result in a valid regexp.

This extra check could help prevent invalid expressions like `"a" matches ("/a/" || "/b/")` where one could mistake `"/a/" || "/b/"` as being a valid regexp (when the correct approach would've been `"a" matches "/a|b/"`)

Commits
-------

e0fbc7e [ExpressionLanguage] Fix matches to handle booleans being used as regexp
symfony-splitter pushed a commit to symfony/expression-language that referenced this pull request Oct 6, 2024
…g used as regexp (ivantsepp)

This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

[ExpressionLanguage] Fix matches to handle booleans being used as regexp

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | n/a
| License       | MIT

I'm marking this as a bug fix but this could be seen as a "new feature" as existing `matches` syntax functionality works just fine.

I wanted to build on top of the work done at symfony/symfony#45875. This handles invalid regular expressions and also does an extra check inside the `compile` method. It checks the right hand side for a `ConstantNode` and validates that it's a valid regexp. The idea is that we can go **even further** and check for `BinaryNode` because in most cases, this is an invalid regexp since a boolean usually returned. The exception is `~` which is for string concatenation since that could result in a valid regexp.

This extra check could help prevent invalid expressions like `"a" matches ("/a/" || "/b/")` where one could mistake `"/a/" || "/b/"` as being a valid regexp (when the correct approach would've been `"a" matches "/a|b/"`)

Commits
-------

e0fbc7ee02 [ExpressionLanguage] Fix matches to handle booleans being used as regexp
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.

3 participants