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:
Fabien Potencier 2014-07-23 09:58:41 +02:00
commit 0b5348ea3a
1 changed files with 1 additions and 1 deletions

View File

@ -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));
}
}