html_safe + interpolate (%) == boom #107

Closed
grosser opened this Issue Sep 16, 2011 · 5 comments

Comments

Projects
None yet
4 participants
@grosser

grosser commented Sep 16, 2011

require 'i18n/core_ext/string/interpolate'
require 'active_support/core_ext/string/output_safety'
"%{a}" %{:a => 1} == '1' # fine
"%{a}".html_safe % {:a => 1} == '1' # BOOOM

NoMethodError: undefined method `to_sym' for nil:NilClass
    from /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/i18n-0.6.0/lib/i18n/core_ext/string/interpolate.rb:92:in `%'
    from /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/activesupport-3.1.0/lib/active_support/core_ext/string/output_safety.rb:140:in `gsub'
    from /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/activesupport-3.1.0/lib/active_support/core_ext/string/output_safety.rb:140:in `gsub'
    from /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/i18n-0.6.0/lib/i18n/core_ext/string/interpolate.rb:88:in `%'
    from (irb):4
@egze

This comment has been minimized.

Show comment
Hide comment
@egze

egze Sep 18, 2011

How dangerous is putting this in the initializers? From the looks of it, it fixes the error.

module ActiveSupport
  class SafeBuffer < String

    def %(*args)
      to_str.% *args
    end
  end
end

egze commented Sep 18, 2011

How dangerous is putting this in the initializers? From the looks of it, it fixes the error.

module ActiveSupport
  class SafeBuffer < String

    def %(*args)
      to_str.% *args
    end
  end
end
@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Sep 19, 2011

works for me :D

grosser commented Sep 19, 2011

works for me :D

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 18, 2011

would be nice to have a real solution to this issue...

grosser commented Nov 18, 2011

would be nice to have a real solution to this issue...

@brodock

This comment has been minimized.

Show comment
Hide comment
@brodock

brodock Dec 22, 2011

Another temporary workaround would be to place .html_safe after the translate method, like:

 I18n.t('translation.key', :default => 'sometext %{interp}', :interp => '<b>stuff</b>').html_safe

brodock commented Dec 22, 2011

Another temporary workaround would be to place .html_safe after the translate method, like:

 I18n.t('translation.key', :default => 'sometext %{interp}', :interp => '<b>stuff</b>').html_safe

kurtzhan pushed a commit to kurtzhan/jugglingchina that referenced this issue Mar 28, 2015

Fixing I18n errors related to html_safe. There is already a bug repor…
…t for this problem here: svenfuchs/i18n#107 but no fix released yet, so going to workaround as it has no side effect.
@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Nov 3, 2016

Collaborator

I can no longer reproduce this bug. I used the code from the OP.

require 'i18n/core_ext/string/interpolate'
require 'active_support/core_ext/string/output_safety'
"%{a}" %{:a => 1} == '1' # fine
"%{a}".html_safe % {:a => 1} == '1' # No boom.

Closing this issue.

Collaborator

radar commented Nov 3, 2016

I can no longer reproduce this bug. I used the code from the OP.

require 'i18n/core_ext/string/interpolate'
require 'active_support/core_ext/string/output_safety'
"%{a}" %{:a => 1} == '1' # fine
"%{a}".html_safe % {:a => 1} == '1' # No boom.

Closing this issue.

@radar radar closed this Nov 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment