minor #11441 [Translator] Optimize assertLocale regexp (Jérémy Derussé)
This PR was merged into the 2.3 branch.
Discussion
----------
[Translator] Optimize assertLocale regexp
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Optimize regexp by remove unused variable and using anchored regex.
Thanks @Tobion
Commits
-------
537c39b
Optimize assertLocale regexp
This commit is contained in:
commit
0b5348ea3a
@ -308,7 +308,7 @@ class Translator implements TranslatorInterface
|
||||
*/
|
||||
private function assertValidLocale($locale)
|
||||
{
|
||||
if (0 !== preg_match('/[^a-z0-9@_\\.\\-]+/i', $locale, $match)) {
|
||||
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid locale: %s.', $locale));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user