Cover and document the matches operator throwing on an invalid UTF-8 subject

This commit is contained in:
Fabien Potencier
2026-09-18 17:15:53 +01:00
parent 5c1be030c5
commit 1ee9dae55a
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
* Fix the sandbox resolving `use` trait templates before checking that the `use` tag is allowed
* Fix `html_attr` dropping `style` declarations whose value is `0`, `0.0` or `'0'`
* Fix the `default` filter fallback emitting an undefined variable warning when it uses the null-safe operator
* Fix the `matches` operator silently treating PCRE execution errors as non-matches
* Fix the `matches` operator silently treating PCRE execution errors as non-matches; it now throws a `RuntimeError`
* Fix `TemplateWrapper::streamBlock()`, `TemplateWrapper::hasBlock()`, and `TemplateWrapper::getBlockNames()` omitting environment globals
* Fix exceptions from dynamic parent expressions escaping without template context
* Add the `BlockChain` class to compose blocks from multiple templates without using template internals
@@ -0,0 +1,8 @@
--TEST--
Twig reports a PCRE failure when the "matches" subject is not valid UTF-8
--TEMPLATE--
{{ subject matches regexp }}
--DATA--
return ['subject' => "\xC3\x28abc", 'regexp' => '/^\p{L}+$/u'];
--EXCEPTION--
Twig\Error\RuntimeError: Regexp "/^\p{L}+$/u" passed to "matches" failed: Malformed UTF-8 characters, possibly incorrectly encoded in "index.twig" at line 2.