diff --git a/lib/rack/contrib/locale.rb b/lib/rack/contrib/locale.rb index 0dbccc2..9e76dfd 100644 --- a/lib/rack/contrib/locale.rb +++ b/lib/rack/contrib/locale.rb @@ -75,7 +75,7 @@ def user_preferred_locale(header) matched_locale = I18n.available_locales.find { |al| match?(al, locale) } if locale if !locale && !matched_locale matched_locale = locales.reverse.find { |locale| I18n.available_locales.any? { |al| variant_match?(al, locale) } } - matched_locale = matched_locale[0,2] if matched_locale + matched_locale = matched_locale[0,2].downcase if matched_locale end matched_locale else diff --git a/test/spec_rack_locale.rb b/test/spec_rack_locale.rb index 2bdfbd8..601fcc7 100644 --- a/test/spec_rack_locale.rb +++ b/test/spec_rack_locale.rb @@ -75,6 +75,10 @@ def enforce_available_locales(enforce) _(response_with_languages('pt;Q=0.9,es-CL').body).must_equal('es') end + specify 'should match languages with variants case insensitively' do + _(response_with_languages('pt;Q=0.9,ES-CL').body).must_equal('es') + end + specify 'should skip * if it is followed by other languages' do _(response_with_languages('*,dk;q=0.5').body).must_equal('dk') end