Permalink
Browse files

Prefer an exact match over a prefix match

  • Loading branch information...
tomhughes committed Feb 14, 2012
1 parent d784356 commit 9d0243b0b40b5ac3b5e7ea5a406541e444947918
Showing with 2 additions and 3 deletions.
  1. +2 −3 lib/http_accept_language/parser.rb
@@ -56,9 +56,8 @@ def preferred_language_from(array)
#
def compatible_language_from(available_languages)
user_preferred_languages.map do |preferred|
- available_languages.find do |available|
- available.to_s =~ /^#{Regexp.escape(preferred.to_s)}(-|$)/
- end
+ available_languages.find { |available| available.to_s == preferred.to_s } ||
+ available_languages.find { |available| available.to_s =~ /^#{Regexp.escape(preferred.to_s)}-/ }
end.compact.first
end

0 comments on commit 9d0243b

Please sign in to comment.