[PATCH conductor] Fix undefined method `<=>' for :"fr-FR":Symbol

Imre Farkas ifarkas at redhat.com
Fri Mar 9 14:06:11 UTC 2012


On 03/08/2012 10:41 PM, Matt Wagner wrote:
> On Thu, Mar 08, 2012 at 03:06:47PM +0100, ifarkas at redhat.com wrote:
>> From: Imre Farkas<ifarkas at redhat.com>
>>
>> ---
>>   src/app/controllers/application_controller.rb |    2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/src/app/controllers/application_controller.rb b/src/app/controllers/application_controller.rb
>> index 4c3347f..e646e6d 100644
>> --- a/src/app/controllers/application_controller.rb
>> +++ b/src/app/controllers/application_controller.rb
>> @@ -348,7 +348,7 @@ class ApplicationController<  ActionController::Base
>>       languages.each do |language|
>>         language += ";q=1.0" unless language.match(";q=\d+\.\d+")
>>         lang_code, lang_weight = language.split(";q=")
>> -      lang_code = lang_code.gsub(/-[a-z]+$/i) { |x| x.upcase }.to_sym
>> +      lang_code = lang_code.gsub(/-[a-z]+$/i) { |x| x.upcase }
>>         prefs<<  [lang_weight, lang_code]
>>       end
>>       # This is slightly abusing array sorting
>> --
>> 1.7.6.5
>
> Is this associated with a BZ? I can't seem to reproduce the error.
> However, in poking around, I think I found another bug in this
> detect_locale code. With some debugging added, I see:
>
>   *** ordered languages: ["fr-FR", "en-US", "en"]
>   *** Available: [:ja, :fr, :cs, :en]
>
> I don't want to step in too far here without knowing exactly what was
> going on, but I think this exposes two other problems with the language
> detection code:
>
> (1) I18n.available_locales returns an array of symbols for me, so we'll
> end up comparing :fr to "fr". If we drop the to_sym above, I think we
> need to to_s the locales from I18n.available_locales.
>
> (2) We don't have any country-specific extensions, and we're looking for
> an exact match only. Since my browser wants "fr-FR", our code won't
> find "fr" (or :fr) as a match. We should either do some more involved
> matching ("If we have fr-FR, use that, otherwise, fr is good
> enough..."), OR we should just drop the whole "-FR" extension from
> incoming locales, if we don't think we're ever going to have en-US.yml
> versus en-GB.yml.
>
> I don't know if this is fixing a specific bug, so if what I've mentioned
> ends up being off-topic, I can make this a separate BZ and take it.
>
> -- Matt

There's no BZ for what it is intended to solve. I randomly get this 
error message but wasn't able to reproduce it consistently on its own. 
How I was able to reproduce is with the Quick Locale Swithcher Firefox 
extension. Set the locale to fr-FR on a new page then go to conductor.
In this case for me env['HTTP_ACCEPT_LANGUAGE'] = 
"en-US,en;q=1.0,fr-FR,fr;q=0.8,en-us;q=0.5,en;q=0.3"
The problem occurs during the sort call since the <=> operator is not 
defined for symbols.

I discussed the problem and this quick fix with Jozef but since you are 
absolutely right in both assertions it may be worth creating a new BZ. 
You also can assign it to me if you want and I will take care of it.

Imre



More information about the aeolus-devel mailing list