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
Wrong argument for twig_matches #3801
Comments
It comes from the usage of the |
the variable "result" shouldn't be empty in any way because of the if statement around the include block |
I don't see any usage of |
If I remove the code snippet shown above the template renders as expected. There is no other code involved |
Then please share the content of the included template. The error is probably somewhere inside it. |
The included template was made empty to test if the error is inside it, so the error is within the include |
Then please share the stack trace of the exception to see where this |
After investigating the error and rollback to TWIG 3.4.3 and now re-upgrade to TWIG 3.5.0 the error seems gone. Strange behavior anyway. I cleared cache, deleted all cache related files, so something went wrong while installing TWIG 3.5.0 over 3.4.3 Sorry for the back and forth and this false report. I think this issue can be closed. If I encounter any more errors after deployment I'll get back |
@stof I now have same error. Please see stack trace:
call in Controller:
Template:
AllFields.csv.twig is empty for testing, error occurs before |
An error happening in an empty template does not make sense to me. |
Cache was cleared several times, vendor folder deleted and reinstalled, no change. Please see content of var/cache/dev/twig/12/120b453c0c68443f04ae729510c089ca.php
|
Seems to be cache related issue in combination with empty and not empty templates, where twig_matches takes place. Doesn't matter if I'm in dev or prod environment. For now it is working again after fixing the "matches" part in the sub template. Somehow it was not recognized by TWIG at all that the template was empty and the previous code was executed... Sorry for this confusion :/ |
Imho this change in 3.5.0 might break BC, preg_match accepted null for the second parameter (PHP 7.4). Now you get the TypeError. Easy to fix with |default("") but I wasn't expecting that. |
I also ran into this BC-breaking change. Just to be super clear, here's the trivial reproduce case: {{ null matches '' }} As pointed out by uwej711, it's easy to fix, but unexpected. Given that Twig is usually very lenient, I think this should be changed. This was introduced in #3687 to guard against invalid regex patterns. @stof I'd be happy to create a PR with - function twig_matches(string $regexp, string $str)
+ function twig_matches(string $regexp, ?string $str) What do you think? |
…942) This PR was merged into the 3.x branch. Discussion ---------- Restores the leniency of the `matches` twig comparison Restores the leniency of the `matches` twig comparison, allowing null subject to result in a non-match. Resolves BC break introduced in PR #3687 ref in #3801 (comment) As per pattern in #3617 Commits ------- f136668 Restores the leniency of the `matches` twig comparison, allowing null subject to result in a non-match.
BC break fixed in #3809 |
After upgrading to TWIG v3.5.0 (coming from v3.4.3) I get a strange error and as my knowledge of the TWIG codebase is limited, I'm not able to get whats the fault.
Error:
twig_matches(): Argument #2 ($str) must be of type string, null given
Calling template part:
result is an array passed to a sub template. This works in v3.4.3 but not in v3.5.0
The text was updated successfully, but these errors were encountered: