Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

interning empty string

#1926

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'

Reported by Nicholas Faiz · February 10th, 2009 @ 12:59 AM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Nicholas Faiz
    Nicholas Faiz

    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'
    

    February 10th, 2009 @ 01:05 AM

  2. Nicholas Faiz
    Nicholas Faiz

    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.

    February 10th, 2009 @ 01:21 AM

  3. Nicholas Faiz
    Nicholas Faiz

    Sorry, this was on 2.3 rc1

    February 10th, 2009 @ 01:23 AM

  4. Pratik
    Pratik
    • 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 !

    March 8th, 2009 @ 12:08 AM

  5. Evgeniy Dolzhenko
    Evgeniy Dolzhenko
    • 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.

    November 5th, 2009 @ 11:47 AM

  6. Wildgoose
    Wildgoose

    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
    

    November 25th, 2009 @ 07:04 PM

  7. Jeremy Kemper
    Jeremy Kemper

    It's wontfix because it's a bug in the bundled i18n library.

    November 26th, 2009 @ 12:42 AM

  8. Evgeniy Dolzhenko