10000 Prevent creating empty keys when key ends with a period · symfony/symfony@e3a062a · GitHub
[go: up one dir, main page]

Skip to content

Commit e3a062a

Browse files
committed
Prevent creating empty keys when key ends with a period
1 parent 7aaa92a commit e3a062a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Symfony/Component/Translation/Tests/Util/ArrayConverterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ public static function messagesData()
6969
],
7070
],
7171
],
72+
[
73+
// input
74+
[
75+
'foo.' => 'foo.',
76+
'bar.' => 'bar.',
77+
'foo bar.' => 'foo bar.',
78+
],
79+
// expected output
80+
[
81+
'foo' => 'foo.',
82+
'bar' => 'bar.',
83+
'foo bar' => 'foo bar.',
84+
],
85+
],
7286
];
7387
}
7488
}

src/Symfony/Component/Translation/Util/ArrayConverter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ private static function &getElementByPath(array &$tree, array $parts)
6565
$elem = &$elem[implode('.', \array_slice($parts, $i))];
6666
break;
6767
}
68+
69+
if (empty($part)) {
70+
/* Prevent creating empty keys when string ends with period, example:
71+
* 'foo.'
72+
*
73+
* Instead of:
74+
* 'foo':
75+
* '' : 'foo.'
76+
*
77+
* We ensure thr following:
78+
* 'foo': 'foo.'
79+
*/
80+
$parentOfElem = &$elem;
81+
$elem = $parentOfElem;
82+
83+
continue;
84+
}
85+
6886
$parentOfElem = &$elem;
6987
$elem = &$elem[$part];
7088
}

0 commit comments

Comments
 (0)
0