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

Skip to content

[ExpressionLanguage] Matches throws error for null values #45926

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

Closed
ausi opened this issue Apr 3, 2022 · 4 comments
Closed

[ExpressionLanguage] Matches throws error for null values #45926

ausi opened this issue Apr 3, 2022 · 4 comments

Comments

@ausi
Copy link
Contributor

ausi commented Apr 3, 2022

Symfony version(s) affected

5.4.7

Description

In #45875 a behavior change was introduced.

How to reproduce

Previously the following code worked as expected:

(new ExpressionLanguage)->evaluate('foo matches "/bar/"', ['foo' => null]);

Since version 5.4.7 this now throws a TypeError: Symfony\Component\ExpressionLanguage\Node\BinaryNode::evaluateMatches(): Argument #2 ($str) must be of type string, null given

Possible Solution

If this is considered a bug or a BC break I’m happy to create a pull request to fix this (including a deprecation notice for non-string values I’d assume).

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Apr 3, 2022

To me it looks sensible to return early if the token to match is null but not a string.

@nicolas-grekas
Copy link
Member

Up for a PR @ausi? We should just accept null next to string and handle it as the empty string, since that's always been the behavior.

@ausi
Copy link
Contributor Author

ausi commented Apr 3, 2022

Up for a PR @ausi?

Yes, will do.

@ausi
Copy link
Contributor Author

ausi commented Apr 3, 2022

Done: #45928

@ausi ausi closed this as completed Apr 3, 2022
fabpot added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants