From f0b4bf216d3899088a968ebfa832ed07abfc5552 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 3 Nov 2026 11:18:05 +0100 Subject: [PATCH 1/2] #408 - Regular expressions: validate the patterns with the configuration, throw on PCRE errors instead of "no match" Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + docs/reference/traits/condition_trait.md | 5 +- .../transformers/preg_filter_transformer.md | 6 +- .../transformers/preg_match_transformer.md | 4 ++ .../transformers/slugify_transformer.md | 2 +- src/Transformer/ConditionTrait.php | 18 +++++ src/Transformer/PregFilterTransformer.php | 21 +++++- src/Transformer/Regex.php | 61 +++++++++++++++++ .../String/PregMatchTransformer.php | 11 ++- src/Transformer/String/SlugifyTransformer.php | 21 +++--- tests/Task/FilterTaskTest.php | 45 ++++++++++++ .../Array/ArrayFilterTransformerTest.php | 1 + .../Transformer/PregFilterTransformerTest.php | 38 +++++++++++ tests/Transformer/RegexTest.php | 68 +++++++++++++++++++ .../String/PregMatchTransformerTest.php | 36 ++++++++++ .../String/SlugifyTransformerTest.php | 9 +++ tests/Transformer/UnsetTransformerTest.php | 1 + 17 files changed, 333 insertions(+), 15 deletions(-) create mode 100644 src/Transformer/Regex.php create mode 100644 tests/Transformer/RegexTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 88dc9dd6..00f291a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Latest * [#392](https://github.com/cleverage/process-bundle/issues/392) Documentation: reset of the process configurations between two messages of a worker (`kernel.reset`, #355), permissions of the JSON buffer of `process_launcher`, `ProcessManager` subclasses in `UPGRADE.md` (v5.5), broken link in the CHANGELOG. ## Fixes +* [#408](https://github.com/cleverage/process-bundle/issues/408) Regular expressions of `preg_match`, `preg_filter`, `slugify` (`replace`) and of the conditions (`match_regexp`, `not_match_regexp` of `filter`, `column_aggregator`, `array_filter`, `unset`): an invalid pattern is rejected when the options are resolved (`InvalidOptionsException`), instead of a PHP warning with the first value then "no match"; a PCRE error while matching (invalid UTF-8 with the `u` modifier, backtracking limit) throws an `UnexpectedValueException`, instead of being taken for "no match" (both `match_regexp` and `not_match_regexp` excluded the input). Update documentation, add tests. * [#402](https://github.com/cleverage/process-bundle/issues/402) `date_parser`: a date or a time out of range (`2024-02-31`, `25:61`), parsed by `\DateTime::createFromFormat()` with a warning and overflowing to the next month or day, throws an `UnexpectedValueException`, as documented for a value that cannot be parsed. A scalar (e.g. an `int` timestamp with the `U` format) or `\Stringable` input is cast to string, an array or another object throws an `UnexpectedValueException` instead of a `TypeError`. Update documentation, add tests. * [#398](https://github.com/cleverage/process-bundle/issues/398) Transformers edge cases. `trim`: a `charlist` with multibyte characters is applied with `mb_trim()` (it produced invalid UTF-8). `convert_value`: with `keep_missing` and `auto_cast`, the input itself is returned, as documented, not its value cast to string. `multi_replace`: the numeric keys of `replace_mapping` no longer throw a `TypeError`, and a replacement that is not a scalar is rejected with the configuration. Conditions (`filter`, `column_aggregator`, `array_filter`, `unset`): the list form of `empty` / `not_empty` (`not_empty: ['[email]']`), described by the documentation, and the numeric property paths no longer throw a `TypeError`. `hash`: an array or a non-`Stringable` object throws an `UnexpectedValueException` (an array was hashed as the string `Array`). The empty `delimiter` of `explode`, an invalid `format` of `sprintf` and an unknown `class` of `instantiate` are rejected with the configuration, not with the first value. Update documentation, add tests. * [#400](https://github.com/cleverage/process-bundle/issues/400) `slugify`: new `strip_tags` option (`true` by default) to keep a text containing a `<` that is not HTML (`strip_tags()` removed everything after it); the result is lowercased with `mb_strtolower()`; a scalar or `\Stringable` input is cast to string, `null`, an array or another object throws an `UnexpectedValueException` instead of a `TypeError`. Documentation: the default transliterator removes the letters that are not decomposed (`Cœur` becomes `c_ur`), `Any-Latin; Latin-ASCII` is recommended. Add tests. diff --git a/docs/reference/traits/condition_trait.md b/docs/reference/traits/condition_trait.md index f818e04b..c8b21d66 100644 --- a/docs/reference/traits/condition_trait.md +++ b/docs/reference/traits/condition_trait.md @@ -28,8 +28,9 @@ Provide a configurable set of matching rules, used by tasks and transformers to | `match_regexp` | `array` | | `[]` | `path => pattern`: the value at `path`, cast to string, must match the regular expression | | `not_match_regexp` | `array` | | `[]` | `path => pattern`: the value at `path`, cast to string, must not match the regular expression | -An invalid regular expression makes both `match_regexp` and `not_match_regexp` fail. In debug mode, the PHP warning -of `preg_match()` is converted into an exception by the Symfony error handler: the task fails. +An invalid regular expression is rejected with an `InvalidOptionsException` when the options are resolved. A PCRE +error while matching a value (e.g. invalid UTF-8 with the `u` modifier, backtracking limit reached) throws an +`UnexpectedValueException` with the PCRE error message, instead of being taken for "no match". ## Usage diff --git a/docs/reference/transformers/preg_filter_transformer.md b/docs/reference/transformers/preg_filter_transformer.md index 90984880..a30212f3 100644 --- a/docs/reference/transformers/preg_filter_transformer.md +++ b/docs/reference/transformers/preg_filter_transformer.md @@ -19,7 +19,11 @@ Any value that can be cast to string. Possible outputs ---------------- -`string|null`: the replaced string, or `null` if no pattern matches (or on regex error). +`string|null`: the replaced string, or `null` if no pattern matches. + +An invalid regular expression is rejected with an `InvalidOptionsException` when the options are resolved. A PCRE +error while matching (e.g. invalid UTF-8 with the `u` modifier, backtracking limit reached) throws an +`UnexpectedValueException` with the PCRE error message, instead of being taken for "no match". Options ------- diff --git a/docs/reference/transformers/preg_match_transformer.md b/docs/reference/transformers/preg_match_transformer.md index b9cb6146..53a1dbb5 100644 --- a/docs/reference/transformers/preg_match_transformer.md +++ b/docs/reference/transformers/preg_match_transformer.md @@ -22,6 +22,10 @@ Possible outputs `preg_match`) * `null` if the input is `null` or an empty string +An invalid regular expression is rejected with an `InvalidOptionsException` when the options are resolved. A PCRE +error while matching (e.g. invalid UTF-8 with the `u` modifier, backtracking limit reached) throws an +`UnexpectedValueException` with the PCRE error message, instead of being taken for "no match". + Options ------- diff --git a/docs/reference/transformers/slugify_transformer.md b/docs/reference/transformers/slugify_transformer.md index a620d656..113057fb 100644 --- a/docs/reference/transformers/slugify_transformer.md +++ b/docs/reference/transformers/slugify_transformer.md @@ -31,7 +31,7 @@ Options | Code | Type | Required | Default | Description | |------------------|----------|:--------:|------------------------------------------|-----------------------------------------------------------------------------------------| | `transliterator` | `string` | | `'NFD; [:Nonspacing Mark:] Remove; NFC'` | Transliterator identifier, passed to `\Transliterator::create()` (see Notes) | -| `replace` | `string` | | `'/[^a-z0-9]+/'` | Regular expression of the characters to replace (applied on the lowercased string) | +| `replace` | `string` | | `'/[^a-z0-9]+/'` | Regular expression of the characters to replace (applied on the lowercased string), checked with the configuration | | `separator` | `string` | | `'_'` | Replacement string, also trimmed from both ends of the result | | `strip_tags` | `bool` | | `true` | Strip the HTML tags with `strip_tags()`, which removes everything after a `<` that does not open a tag (`'TomsetAllowedTypes('empty', 'array'); $resolver->setAllowedTypes('not_match_regexp', 'array'); $resolver->setAllowedTypes('match_regexp', 'array'); + // Rejected with the configuration: an invalid pattern made both match_regexp and not_match_regexp fail + foreach (['match_regexp', 'not_match_regexp'] as $option) { + $resolver->setNormalizer($option, static function (Options $options, array $value) use ($option): array { + foreach ($value as $pattern) { + if (!\is_string($pattern)) { + throw new InvalidOptionsException(\sprintf('The patterns of the "%s" option must be strings, %s given.', $option, get_debug_type($pattern))); + } + Regex::validate($pattern, $option); + } + + return $value; + }); + } // The list form of empty / not_empty (e.g. not_empty: ['[email]']): the values are the property paths foreach (['empty', 'not_empty'] as $option) { $resolver->setNormalizer($option, static function (Options $options, array $value): array { @@ -146,6 +160,10 @@ protected function checkValue( if ($regexpMode) { $pregMatch = preg_match($value, (string) $currentValue); + // A PCRE error (e.g. invalid UTF-8 with the "u" modifier) made both match_regexp and not_match_regexp fail + if (false === $pregMatch) { + Regex::checkLastError($value); + } if ($shouldMatch && (false === $pregMatch || 0 === $pregMatch)) { return false; diff --git a/src/Transformer/PregFilterTransformer.php b/src/Transformer/PregFilterTransformer.php index cba994d2..bc42e104 100644 --- a/src/Transformer/PregFilterTransformer.php +++ b/src/Transformer/PregFilterTransformer.php @@ -33,7 +33,13 @@ public function transform(mixed $value, array $options = []): array|string|null $pattern = $options['pattern']; $replacement = $options['replacement']; - return preg_filter($pattern, $replacement, (string) $value); + $result = preg_filter($pattern, $replacement, (string) $value); + // null is also "no match": a PCRE error (e.g. invalid UTF-8 with the "u" modifier) is not + if (null === $result) { + Regex::checkLastError(\is_array($pattern) ? implode('", "', $pattern) : $pattern); + } + + return $result; } /** @@ -49,6 +55,19 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setRequired(['pattern', 'replacement']); $resolver->setAllowedTypes('pattern', ['string', 'array']); $resolver->setAllowedTypes('replacement', ['string', 'array']); + $resolver->setNormalizer( + 'pattern', + static function (Options $options, string|array $value): string|array { + foreach ((array) $value as $pattern) { + if (!\is_string($pattern)) { + throw new InvalidOptionsException(\sprintf('The patterns of the "pattern" option must be strings, %s given.', get_debug_type($pattern))); + } + Regex::validate($pattern); + } + + return $value; + } + ); $resolver->setNormalizer( 'replacement', static function (Options $options, string|array $value): string|array { diff --git a/src/Transformer/Regex.php b/src/Transformer/Regex.php new file mode 100644 index 00000000..5476d684 --- /dev/null +++ b/src/Transformer/Regex.php @@ -0,0 +1,61 @@ +setRequired(['pattern']); $resolver->setAllowedTypes('pattern', ['string']); + $resolver->setNormalizer('pattern', static fn (Options $options, string $pattern): string => Regex::validate($pattern)); $resolver->setDefault('flags', 0); $resolver->setAllowedTypes('flags', ['int']); $resolver->setDefault('offset', 0); diff --git a/src/Transformer/String/SlugifyTransformer.php b/src/Transformer/String/SlugifyTransformer.php index 9f121d15..0dad8ba8 100644 --- a/src/Transformer/String/SlugifyTransformer.php +++ b/src/Transformer/String/SlugifyTransformer.php @@ -15,6 +15,7 @@ use CleverAge\ProcessBundle\Exception\UnexpectedValueException; use CleverAge\ProcessBundle\Transformer\ConfigurableTransformerInterface; +use CleverAge\ProcessBundle\Transformer\Regex; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -47,15 +48,18 @@ public function transform(mixed $value, array $options = []): string $string = strip_tags($string); } - return trim( - (string) preg_replace( - $options['replace'], - (string) $options['separator'], - // The characters left by the transliterator may be multibyte - mb_strtolower(trim($string)) - ), - $options['separator'] + $slug = preg_replace( + $options['replace'], + (string) $options['separator'], + // The characters left by the transliterator may be multibyte + mb_strtolower(trim($string)) ); + if (null === $slug) { + // A PCRE error gave an empty slug + Regex::checkLastError($options['replace']); + } + + return trim((string) $slug, $options['separator']); } /** @@ -81,6 +85,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedTypes('transliterator', ['string']); $resolver->setAllowedTypes('replace', ['string']); $resolver->setAllowedTypes('separator', ['string']); + $resolver->setNormalizer('replace', static fn (Options $options, string $pattern): string => Regex::validate($pattern, 'replace')); $resolver->setNormalizer( 'transliterator', diff --git a/tests/Task/FilterTaskTest.php b/tests/Task/FilterTaskTest.php index 12fcef91..4d53af00 100644 --- a/tests/Task/FilterTaskTest.php +++ b/tests/Task/FilterTaskTest.php @@ -34,6 +34,7 @@ #[\PHPUnit\Framework\Attributes\UsesClass(ContextualOptionResolver::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessHistory::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessState::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class FilterTaskTest extends TestCase { /** @@ -200,4 +201,48 @@ public function testListFormOfEmptyAndNotEmpty(): void $this->assertTrue($this->execute(['not_empty' => ['[email]']], ['email' => ''])->isSkipped()); $this->assertTrue($this->execute(['empty' => ['[deleted_at]']], ['deleted_at' => 'yesterday'])->isSkipped()); } + + /** + * @return iterable}> + */ + public static function provideInvalidRegexpOptions(): iterable + { + yield 'match_regexp' => [['match_regexp' => ['[name]' => '/(a/']]]; + yield 'not_match_regexp' => [['not_match_regexp' => ['[name]' => '/(a/']]]; + yield 'not a string' => [['match_regexp' => ['[name]' => 1]]]; + } + + /** + * An invalid pattern made both match_regexp and not_match_regexp fail: every input was filtered out. + * + * @param array $options + */ + #[DataProvider('provideInvalidRegexpOptions')] + public function testInvalidRegexpIsRejected(array $options): void + { + $this->expectException(InvalidOptionsException::class); + + $this->execute($options, ['name' => 'a']); + } + + /** + * @return iterable + */ + public static function provideRegexpOptions(): iterable + { + yield 'match_regexp' => ['match_regexp']; + yield 'not_match_regexp' => ['not_match_regexp']; + } + + /** + * A PCRE error made both match_regexp and not_match_regexp fail: the input was filtered out. + */ + #[DataProvider('provideRegexpOptions')] + public function testPcreErrorThrows(string $option): void + { + $this->expectException(\CleverAge\ProcessBundle\Exception\UnexpectedValueException::class); + $this->expectExceptionMessage('The regular expression "/a/u" has failed: Malformed UTF-8 characters'); + + $this->execute([$option => ['[name]' => '/a/u']], ['name' => "a\xff"]); + } } diff --git a/tests/Transformer/Array/ArrayFilterTransformerTest.php b/tests/Transformer/Array/ArrayFilterTransformerTest.php index 422f2b04..19ce849e 100644 --- a/tests/Transformer/Array/ArrayFilterTransformerTest.php +++ b/tests/Transformer/Array/ArrayFilterTransformerTest.php @@ -19,6 +19,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; #[\PHPUnit\Framework\Attributes\CoversClass(ArrayFilterTransformer::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class ArrayFilterTransformerTest extends TestCase { public function testWholeValueConditionOnScalars(): void diff --git a/tests/Transformer/PregFilterTransformerTest.php b/tests/Transformer/PregFilterTransformerTest.php index 746f5dc9..2fd5640b 100644 --- a/tests/Transformer/PregFilterTransformerTest.php +++ b/tests/Transformer/PregFilterTransformerTest.php @@ -22,6 +22,7 @@ #[\PHPUnit\Framework\Attributes\CoversMethod(PregFilterTransformer::class, 'transform')] #[\PHPUnit\Framework\Attributes\CoversMethod(PregFilterTransformer::class, 'configureOptions')] #[\PHPUnit\Framework\Attributes\CoversMethod(PregFilterTransformer::class, 'getCode')] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class PregFilterTransformerTest extends TestCase { public function testTransformWithStringReplacement(): void @@ -86,4 +87,41 @@ private function resolveOptions(PregFilterTransformer $transformer, array $optio return $resolver->resolve($options); } + + /** + * @return iterable}> + */ + public static function provideInvalidPatterns(): iterable + { + yield 'string' => ['/(a/']; + yield 'array' => [['/a/', '/(a/']]; + yield 'not a string' => [['/a/', 1]]; + } + + /** + * Rejected with the configuration (a PHP warning with the first value, then null as for "no match"). + * + * @param string|array $pattern + */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideInvalidPatterns')] + public function testInvalidPatternIsRejected(string|array $pattern): void + { + $this->expectException(InvalidOptionsException::class); + + $this->resolveOptions(new PregFilterTransformer(), ['pattern' => $pattern, 'replacement' => 'b']); + } + + /** + * A PCRE error was taken for "no match": null. + */ + public function testPcreErrorThrows(): void + { + $transformer = new PregFilterTransformer(); + $options = $this->resolveOptions($transformer, ['pattern' => ['/a/u', '/b/u'], 'replacement' => 'c']); + + $this->expectException(\CleverAge\ProcessBundle\Exception\UnexpectedValueException::class); + $this->expectExceptionMessage('The regular expression "/a/u", "/b/u" has failed: Malformed UTF-8 characters'); + + $transformer->transform("a\xff", $options); + } } diff --git a/tests/Transformer/RegexTest.php b/tests/Transformer/RegexTest.php new file mode 100644 index 00000000..9ec54cb0 --- /dev/null +++ b/tests/Transformer/RegexTest.php @@ -0,0 +1,68 @@ +expectException(InvalidOptionsException::class); + $this->expectExceptionMessage('Invalid regular expression "a" in the "match" option: Delimiter must not be alphanumeric, backslash, or NUL byte'); + + Regex::validate('a', 'match'); + } + + /** + * The error handler of the application (e.g. the Symfony one in debug mode) is restored. + */ + public function testTheErrorHandlerIsRestored(): void + { + $handler = static fn (): bool => true; + set_error_handler($handler); + try { + try { + Regex::validate('/(a/'); + } catch (InvalidOptionsException) { + } + self::assertSame($handler, set_error_handler(null)); + } finally { + restore_error_handler(); + restore_error_handler(); + } + } + + public function testCheckLastError(): void + { + preg_match('/a/u', 'a'); + Regex::checkLastError('/a/u'); + + preg_match('/a/u', "a\xff"); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The regular expression "/a/u" has failed: Malformed UTF-8 characters, possibly incorrectly encoded'); + + Regex::checkLastError('/a/u'); + } +} diff --git a/tests/Transformer/String/PregMatchTransformerTest.php b/tests/Transformer/String/PregMatchTransformerTest.php index 19163b23..611693cc 100644 --- a/tests/Transformer/String/PregMatchTransformerTest.php +++ b/tests/Transformer/String/PregMatchTransformerTest.php @@ -21,6 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; #[\PHPUnit\Framework\Attributes\CoversClass(PregMatchTransformer::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class PregMatchTransformerTest extends TestCase { /** @@ -127,4 +128,39 @@ private function resolveOptions(PregMatchTransformer $transformer, array $option return $resolver->resolve($options); } + + /** + * Rejected with the configuration (a PHP warning with the first value, then no match). + */ + public function testInvalidPatternIsRejected(): void + { + $this->expectException(InvalidOptionsException::class); + $this->expectExceptionMessage('Invalid regular expression "/(a/" in the "pattern" option: Compilation failed: missing closing parenthesis'); + + $this->resolveOptions(new PregMatchTransformer(), ['pattern' => '/(a/']); + } + + /** + * @return iterable + */ + public static function provideModes(): iterable + { + yield 'preg_match' => [false]; + yield 'preg_match_all' => [true]; + } + + /** + * A PCRE error was taken for "no match": an empty array. + */ + #[DataProvider('provideModes')] + public function testPcreErrorThrows(bool $modeAll): void + { + $transformer = new PregMatchTransformer(); + $options = $this->resolveOptions($transformer, ['pattern' => '/a/u', 'mode_all' => $modeAll]); + + $this->expectException(\CleverAge\ProcessBundle\Exception\UnexpectedValueException::class); + $this->expectExceptionMessage('The regular expression "/a/u" has failed: Malformed UTF-8 characters, possibly incorrectly encoded'); + + $transformer->transform("a\xff", $options); + } } diff --git a/tests/Transformer/String/SlugifyTransformerTest.php b/tests/Transformer/String/SlugifyTransformerTest.php index 5b803fdd..979779da 100644 --- a/tests/Transformer/String/SlugifyTransformerTest.php +++ b/tests/Transformer/String/SlugifyTransformerTest.php @@ -22,6 +22,7 @@ #[\PHPUnit\Framework\Attributes\CoversMethod(SlugifyTransformer::class, 'transform')] #[\PHPUnit\Framework\Attributes\CoversMethod(SlugifyTransformer::class, 'configureOptions')] #[\PHPUnit\Framework\Attributes\CoversMethod(SlugifyTransformer::class, 'getCode')] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class SlugifyTransformerTest extends TestCase { public function testTransformWithDefaultOptions(): void @@ -178,4 +179,12 @@ private function resolveOptions(SlugifyTransformer $transformer, array $options return $resolver->resolve($options); } + + public function testInvalidReplaceIsRejected(): void + { + $this->expectException(InvalidOptionsException::class); + $this->expectExceptionMessage('in the "replace" option'); + + $this->resolveOptions(new SlugifyTransformer(), ['replace' => '/[a-z/']); + } } diff --git a/tests/Transformer/UnsetTransformerTest.php b/tests/Transformer/UnsetTransformerTest.php index 7e8621bd..e33a2e69 100644 --- a/tests/Transformer/UnsetTransformerTest.php +++ b/tests/Transformer/UnsetTransformerTest.php @@ -25,6 +25,7 @@ #[\PHPUnit\Framework\Attributes\CoversClass(UnsetTransformer::class)] #[\PHPUnit\Framework\Attributes\UsesTrait(ConditionTrait::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Transformer\Regex::class)] class UnsetTransformerTest extends TestCase { private const INPUT = [ From 42c158eddf36ad5088feab320006a1ed0d359bfc Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 3 Nov 2026 11:23:51 +0100 Subject: [PATCH 2/2] #408 - RegexTest: do not assert the end of the PHP warning, which depends on the PHP version Co-Authored-By: Claude Opus 5.5 --- tests/Transformer/RegexTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Transformer/RegexTest.php b/tests/Transformer/RegexTest.php index 9ec54cb0..6e470786 100644 --- a/tests/Transformer/RegexTest.php +++ b/tests/Transformer/RegexTest.php @@ -30,7 +30,8 @@ public function testValidPattern(): void public function testInvalidPattern(): void { $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('Invalid regular expression "a" in the "match" option: Delimiter must not be alphanumeric, backslash, or NUL byte'); + // The end of the PHP message depends on the version ("or NUL byte" since PHP 8.4) + $this->expectExceptionMessage('Invalid regular expression "a" in the "match" option: Delimiter must not be alphanumeric'); Regex::validate('a', 'match'); }