Skip to content

Commit

Permalink
Fix for the test cases added on Locale::preferred.
Browse files Browse the repository at this point in the history
* It makes the regex more strict regarding what can define a language (Issue UnionOfRAD#386)
  • Loading branch information
greut committed Mar 24, 2012
1 parent da67962 commit c98f67f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions g11n/Locale.php
Expand Up @@ -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;
Expand Down

0 comments on commit c98f67f

Please sign in to comment.