Sha256: a66d2827a03f248d53c75a5c0c91470cb6182a5ac782f76c19e4f27108d871f9

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# Use module_eval so we crash when ERB::Util has not yet been loaded.
ERB::Util.module_eval do

  if private_method_defined? :unwrapped_html_escape # Rails 4.2+

    def unwrapped_html_escape_with_escaping_angular_expressions(s)
      s = s.to_s
      if s.html_safe?
        s
      else
        unwrapped_html_escape_without_escaping_angular_expressions(AngularXss::Escaper.escape(s))
      end
    end

    alias_method :unwrapped_html_escape_without_escaping_angular_expressions, :unwrapped_html_escape
    alias_method :unwrapped_html_escape, :unwrapped_html_escape_with_escaping_angular_expressions

    singleton_class.send(:remove_method, :unwrapped_html_escape)
    module_function :unwrapped_html_escape
    module_function :unwrapped_html_escape_without_escaping_angular_expressions

  else # Rails < 4.2

    def html_escape_with_escaping_angular_expressions(s)
      s = s.to_s
      if s.html_safe?
        s
      else
        html_escape_without_escaping_angular_expressions(AngularXss::Escaper.escape(s))
      end
    end

    alias_method_chain :html_escape, :escaping_angular_expressions

    # Aliasing twice issues a warning "discarding old...". Remove first to avoid it.
    remove_method(:h)
    alias h html_escape

    module_function :h

    singleton_class.send(:remove_method, :html_escape)
    module_function :html_escape
    module_function :html_escape_without_escaping_angular_expressions

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
angular_xss-0.4.1 lib/angular_xss/erb.rb
angular_xss-0.4.0 lib/angular_xss/erb.rb
angular_xss-0.3.1 lib/angular_xss/erb.rb