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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy