From e2cadd6ed48a9e1c96c068c11354c6342568a03f Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 23 May 2010 03:35:59 -0700 Subject: [PATCH] [Haml] Rails 2.3.6 compat: hack around the use of #safe_concat in #capture. Closes gh-178 --- lib/haml/helpers/action_view_mods.rb | 16 ++++++++++++++++ lib/haml/template.rb | 6 +----- lib/haml/util.rb | 12 ++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/haml/helpers/action_view_mods.rb b/lib/haml/helpers/action_view_mods.rb index 77c42715..1ca70604 100644 --- a/lib/haml/helpers/action_view_mods.rb +++ b/lib/haml/helpers/action_view_mods.rb @@ -97,6 +97,22 @@ module ActionView end end + # For some reason, Rails 2.3.6 uses #safe_concat in #capture + # even when XSS support is disabled. + if Haml::Util.ap_2_3_6? + module TextHelper + def concat_with_haml(string, binding = nil) + if is_haml? + haml_buffer.buffer.concat(string) + else + concat_without_haml(string, binding) + end + end + alias_method :concat_without_haml, :concat + alias_method :concat, :concat_with_haml + end + end + module TagHelper def content_tag_with_haml(name, *args, &block) return content_tag_without_haml(name, *args, &block) unless is_haml? diff --git a/lib/haml/template.rb b/lib/haml/template.rb index c5a82562..b5a53eee 100644 --- a/lib/haml/template.rb +++ b/lib/haml/template.rb @@ -64,14 +64,10 @@ else Haml::Template.try_enabling_xss_integration end -require 'action_pack' # Rails 2.3.6 monkeypatches ERB in incompatible ways. # We fix our own subclass of ERB here so the Haml ERB filter # will continue to work. -if defined?(ActionPack::VERSION::MAJOR) && - ActionPack::VERSION::MAJOR == 2 && - ActionPack::VERSION::MINOR == 3 && - ActionPack::VERSION::TINY >= 6 +if Haml::Util.ap_2_3_6? class Haml::Filters::ERB::RealERB def set_eoutvar(compiler, eoutvar = '_erbout') compiler.put_cmd = "#{eoutvar}.concat" diff --git a/lib/haml/util.rb b/lib/haml/util.rb index 114039da..ad9b180b 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -324,6 +324,18 @@ module Haml $1.to_i >= 3)) end + # Returns whether this environment is using ActionPack + # version 2.3.6 (or greater, up until 3.0.0). + # + # @return [Boolean] + def ap_2_3_6? + require 'action_pack' + defined?(ActionPack::VERSION::MAJOR) && + ActionPack::VERSION::MAJOR == 2 && + ActionPack::VERSION::MINOR == 3 && + ActionPack::VERSION::TINY >= 6 + end + # Returns an ActionView::Template* class. # In pre-3.0 versions of Rails, most of these classes # were of the form `ActionView::TemplateFoo`,