Permalink
Browse files

Merge pull request #9 from cacol89/master

Fixed problem for recognizing Latin American Spanish.

Fixes #8
  • Loading branch information...
2 parents 540b750 + aadd1af commit d60a7c697874b24b0ade9f6831bf000dff4ffe31 @iain committed Mar 29, 2012
Showing with 4 additions and 4 deletions.
  1. +2 −2 lib/http_accept_language.rb
  2. +2 −2 test/http_accept_language_test.rb
@@ -13,10 +13,10 @@ def user_preferred_languages
l += ';q=1.0' unless l =~ /;q=\d+\.\d+$/
l.split(';q=')
end.sort do |x,y|
- raise "Not correctly formatted" unless x.first =~ /^[a-z\-]+$/i
+ raise "Not correctly formatted" unless x.first =~ /^[a-z\-0-9]+$/i
y.last.to_f <=> x.last.to_f
end.collect do |l|
- l.first.downcase.gsub(/-[a-z]+$/i) { |x| x.upcase }
+ l.first.downcase.gsub(/-[a-z0-9]+$/i) { |x| x.upcase }
end
rescue # Just rescue anything if the browser messed up badly.
[]
@@ -5,7 +5,7 @@
class MockedCgiRequest
include HttpAcceptLanguage
def env
- @env ||= {'HTTP_ACCEPT_LANGUAGE' => 'en-us,en-gb;q=0.8,en;q=0.6'}
+ @env ||= {'HTTP_ACCEPT_LANGUAGE' => 'en-us,en-gb;q=0.8,en;q=0.6,es-419'}
end
end
@@ -16,7 +16,7 @@ def test_should_return_empty_array
end
def test_should_properly_split
- assert_equal %w{en-US en-GB en}, request.user_preferred_languages
+ assert_equal %w{en-US es-419 en-GB en}, request.user_preferred_languages
end
def test_should_ignore_jambled_header

0 comments on commit d60a7c6

Please sign in to comment.