Skip to content

Commit 5fd18ec

Browse files
committed
[WebProfiler][Translator] Fix TranslationDataCollector should use cloneVar
1 parent 64ab6fc commit 5fd18ec

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

DataCollector/TranslationDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ private function sanitizeCollectedMessages($messages)
101101

102102
if (!isset($result[$messageId])) {
103103
$message['count'] = 1;
104-
$message['parameters'] = !empty($message['parameters']) ? array($message['parameters']) : array();
104+
$message['parameters'] = !empty($message['parameters']) ? array($this->cloneVar($message['parameters'])) : array();
105105
$messages[$key]['translation'] = $this->sanitizeString($message['translation']);
106106
$result[$messageId] = $message;
107107
} else {
108108
if (!empty($message['parameters'])) {
109-
$result[$messageId]['parameters'][] = $message['parameters'];
109+
$result[$messageId]['parameters'][] = $this->cloneVar($message['parameters']);
110110
}
111111

112112
++$result[$messageId]['count'];

Tests/DataCollector/TranslationDataCollectorTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Translation\DataCollectorTranslator;
1515
use Symfony\Component\Translation\DataCollector\TranslationDataCollector;
16+
use Symfony\Component\VarDumper\Cloner\VarCloner;
1617

1718
class TranslationDataCollectorTest extends \PHPUnit_Framework_TestCase
1819
{
@@ -39,6 +40,8 @@ public function testCollectEmptyMessages()
3940

4041
public function testCollect()
4142
{
43+
$cloner = new VarCloner();
44+
4245
$collectedMessages = array(
4346
array(
4447
'id' => 'foo',
@@ -115,9 +118,9 @@ public function testCollect()
115118
'state' => DataCollectorTranslator::MESSAGE_MISSING,
116119
'count' => 3,
117120
'parameters' => array(
118-
array('%count%' => 3),
119-
array('%count%' => 3),
120-
array('%count%' => 4, '%foo%' => 'bar'),
121+
$cloner->cloneVar(array('%count%' => 3)),
122+
$cloner->cloneVar(array('%count%' => 3)),
123+
$cloner->cloneVar(array('%count%' => 4, '%foo%' => 'bar')),
121124
),
122125
'transChoiceNumber' => 3,
123126
),

0 commit comments

Comments
 (0)