Browse files

Make compatible_language_from follow the RFC 2616 selection algorithm

We need to look for the longest matching prefix rather than just the
first language with the same basic language code, otherwise if we have
both zh-CN and zh-TW available then we may select the wrong one as we
will return he first one we see that starts with zh even if the user
had said they preferred a specific variant.
  • Loading branch information...
1 parent 33f9685 commit a24a364ea9465d684378dfc1b5d4211701dadd37 @tomhughes tomhughes committed with May 24, 2010
Showing with 1 addition and 2 deletions.
  1. +1 −2 lib/http_accept_language.rb
@@ -42,9 +42,8 @@ def preferred_language_from(array)
def compatible_language_from(array) do |x|
- x = x.to_s.split("-")[0]
array.find do |y|
- y.to_s.split("-")[0] == x
+ y.to_s =~ /^#{Regexp.escape(x.to_s)}(-|$)/

0 comments on commit a24a364

Please sign in to comment.