diff --git a/.travis.yml b/.travis.yml index 23eadf75c9..c01e9be95a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,5 @@ matrix: allow_failures: - rvm: rbx-3 - gemfile: test/gemfiles/Gemfile.rails-edge - - gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi fast_finish: true script: "bundle exec rake submodules test" diff --git a/lib/haml/railtie.rb b/lib/haml/railtie.rb index 4c17642079..977f5e2c63 100644 --- a/lib/haml/railtie.rb +++ b/lib/haml/railtie.rb @@ -26,7 +26,15 @@ class Railtie < ::Rails::Railtie require "haml/sass_rails_filter" end - if defined? ActionView::Template::Handlers::ERB::Erubi + # Any object under ActionView::Template will be defined as the root constant with the same + # name if it exists. If Erubi is loaded at all, ActionView::Template::Handlers::ERB::Erubi + # will turn out to be a reference to the ::Erubi module. + # In Rails 4.2, calling const_defined? results in odd exceptions, which seems to be + # solved by looking for ::Erubi first. + # However, in JRuby, the const_defined? finds it anyway, so we must make sure that it's + # not just a reference to ::Erubi. + if defined?(::Erubi) && const_defined?('ActionView::Template::Handlers::ERB::Erubi') && + ActionView::Template::Handlers::ERB::Erubi != ::Erubi require "haml/helpers/safe_erubi_template" Haml::Filters::RailsErb.template_class = Haml::SafeErubiTemplate else