diff --git a/CHANGELOG.md b/CHANGELOG.md index 6439b25a..f472158d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2.2.1 under development - Bug #130: Updated `Message::parse()` to correctly support multiple placeholders (@technicated) -- Chg #130: Changed `Message::parse()` to conform to PSR-3, removing support for placeholders with arbitrary names and nested placeholders (@technicated) +- Chg #130, #133: Changed `Message::parse()` to conform to PSR-3 (@technicated, @vjik) ## 2.2.0 December 13, 2025 diff --git a/src/Message.php b/src/Message.php index bc0df4b2..0985e702 100644 --- a/src/Message.php +++ b/src/Message.php @@ -208,7 +208,7 @@ private function parse(string|Stringable $message, array $context): string /** @var string */ return preg_replace_callback( - '/\{([\w\._]+)\}/', + '/\{([\w\.\\\\_]+)\}/', static function (array $matches) use ($context) { [$exist, $value] = ContextValueExtractor::extract($context, $matches[1]); if ($exist) { diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 42ef888e..88634847 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -122,6 +122,46 @@ public function dataParseMessage(): array ['p1' => 'hello', 'p2' => 'world'], 'Placeholder 1: hello - Placeholder 2: world', ], + 'nested-quoted' => [ + 'has "{foo\.ba\\\\r}" placeholder', + ['foo.ba\\r' => 'test'], + 'has "test" placeholder', + ], + 'nested-extended-1' => [ + 'has "{foo\\\.bar}" placeholder', + ['foo\\' => ['bar' => 'test']], + 'has "test" placeholder', + ], + 'nested-extended-2' => [ + 'has "{foo\\\\\\\\.bar}" placeholder', + ['foo\\\\' => ['bar' => 'test']], + 'has "test" placeholder', + ], + 'nested-extended-3' => [ + 'has "{foo\\\.}" placeholder', + ['foo\\' => ['' => 'test']], + 'has "test" placeholder', + ], + 'nested-extended-4' => [ + 'has "{foo\\\\}" placeholder', + ['foo\\' => 'test'], + 'has "test" placeholder', + ], + 'nested-extended-5' => [ + 'has "{foo\.bar.a}" placeholder', + ['foo.bar' => ['a' => 'test']], + 'has "test" placeholder', + ], + 'nested-extended-6' => [ + 'has "{key1\..\.key2\..\.key3}" placeholder', + ['key1.' => ['.key2.' => ['.key3' => 'test']]], + 'has "test" placeholder', + ], + 'nested-extended-7' => [ + 'has "{key1\..\.key2\..\.key3}" placeholder', + ['key1.' => ['.key2.' => ['.key3' => 'test']]], + 'has "test" placeholder', + ], ]; }