Permalink
Browse files

Fix for the test cases added on Locale::preferred.

* It makes the regex more strict regarding what can define a language (Issue #386)
  • Loading branch information...
1 parent da67962 commit c98f67fcce301327269c069ff859c46090d5277c @greut greut committed Mar 24, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 g11n/Locale.php
View
@@ -251,11 +251,11 @@ public static function preferred($request, $available = null) {
* @return array Preferred locales in their canonical form (i.e. `'fr_CA'`).
*/
protected static function _preferredAction($request) {
- $regex = '(?P<locale>[\w\-]+)+(?:;q=(?P<quality>[0-9]+\.[0-9]+))?';
+ $regex = '/^\s*(?P<locale>\w\w(?:[-]\w\w)?)(?:;q=(?P<quality>[0-9]+\.[0-9]+))?\s*$/';
$result = array();
foreach (explode(',', $request->env('HTTP_ACCEPT_LANGUAGE')) as $part) {
- if (preg_match("/{$regex}/", $part, $matches)) {
+ if (preg_match($regex, $part, $matches)) {
$locale = static::canonicalize($matches['locale']);
$quality = isset($matches['quality']) ? $matches['quality'] : 1;
$result[$locale] = $quality;

0 comments on commit c98f67f

Please sign in to comment.