This project is archived and is in readonly mode.
interning empty string
Reported by Nicholas Faiz | February 10th, 2009 @ 12:59 AM | in 2.x
Hi,
I've been seeing frequent errors in my AR validations about interning empty strings, particularly when building a string to add to the errors array.
For example,
def one_home_server if self.home == true preexisting = Server.find_by_country_and_home(self.country, true) if preexisting msg = "A home server already exists. Set home to false there first." errors.add(msg) end end end
Will result in
ArgumentError in 'Server should validate that only one server, locally, can be home server' interning empty string /Users/nick/code/src/clients/zumio/reach-out-global/app/models/server.rb:21:in `one_home_server'
Comments and changes to this ticket
-
Nicholas Faiz February 10th, 2009 @ 01:05 AM
Provoking the error from a debugger breakpoint:
ArgumentError: interning empty string from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb:196:in `to_sym' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb:196:in `normalize_translation_keys' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb:196:in `map' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb:196:in `normalize_translation_keys' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb:101:in `send' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb:101:in `lookup' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb:33:in `translate' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.0/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb:165:in `translate' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.0/lib/active_record/validations.rb:110:in `generate_message' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.0/lib/active_record/validations.rb:48:in `add' from (irb):3:in `send'
-
Nicholas Faiz February 10th, 2009 @ 01:21 AM
Here's a workaround:
errors.add(msg, "invalid")
The normalize_transaction_keys in i18n.rb wasn't protecting itself from nils. Adding a nil check in stopped the error:
def normalize_translation_keys(locale, key, scope) keys = [locale] + Array(scope) + [key] keys = keys.map { |k| k.to_s.split(/\./) } keys.flatten.map { |k| if k then k.to_sym end } end end
It was evidently trying to convert a nil or "" into a sym.
-
Pratik March 8th, 2009 @ 12:08 AM
- State changed from new to wontfix
Can't reproduce. Could you please submit a failng test case ? http://guides.rails.info/contrib... might be helpful as well.
Thanks !
-
Evgeniy Dolzhenko November 5th, 2009 @ 11:47 AM
- Tag set to activesupport, i18n
- Assigned user set to Pratik
Confirmed the issue. Can be easily illustrated from console:
>> I18n.translate(".1.") ArgumentError: interning empty string from /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:197:in `to_sym' from /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:197:in `normalize_translation_keys' from /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:197:in `map' from /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:197:in `normalize_translation_keys'
Attached patch with the test case and fix.
-
Wildgoose November 25th, 2009 @ 07:04 PM
Not sure why this is still "won't fix"? Can we please re-open? It seems that this is also the clue to my bug:
I find using a custom validation message with a ".." in it breaks rails 2.3.4
eg:
validates_inclusion_of :pager_msg_size, :in => 30..500, :message => "enter range between 30..500"I can also see this in the console:
I18n.translate("enter 1..2") ArgumentError: interning empty string
from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:196:in `to_sym' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:196:in `normalize_translation_keys' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:196:in `map' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:196:in `normalize_translation_keys' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb:101:in `send' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb:101:in `lookup' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb:33:in `translate' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:165:in `translate' from (irb):8
-
Jeremy Kemper November 26th, 2009 @ 12:42 AM
It's wontfix because it's a bug in the bundled i18n library.
-
Evgeniy Dolzhenko November 26th, 2009 @ 01:38 PM
- Tag cleared.
Ok, does that mean it should be reported here http://i18n.lighthouseapp.com/projects/14947-ruby-i18n/tickets ?
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>