Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
}

Expand Down
Loading