lib/haml/helpers/action_view_mods.rb in haml-3.0.4 vs lib/haml/helpers/action_view_mods.rb in haml-3.0.5

- old
+ new

@@ -83,20 +83,38 @@ end else module CaptureHelper def capture_with_haml(*args, &block) if Haml::Helpers.block_is_haml?(block) - capture_haml(*args, &block) + str = capture_haml(*args, &block) + return ActionView::NonConcattingString.new(str) if defined?(ActionView::NonConcattingString) + return str else capture_without_haml(*args, &block) end end alias_method :capture_without_haml, :capture alias_method :capture, :capture_with_haml 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? preserve = haml_buffer.options[:preserve].include?(name.to_s) @@ -230,9 +248,30 @@ concat "\n" if block_given? && is_haml? Haml::Helpers::ErrorReturn.new("form_for") if is_haml? end alias_method :form_for_without_haml, :form_for alias_method :form_for, :form_for_with_haml + end + end + end +end + +# Rails 2.3.6 uses #safe_concat in #fragment_for +# rather than using #concat with an #html_safe string. +# This fixes that issue. +if Haml::Util.ap_2_3_6? + module ActionController::Caching::Fragments + def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc: + if perform_caching + if cache = read_fragment(name, options) + buffer.concat(cache.html_safe) + else + pos = buffer.length + block.call + write_fragment(name, buffer[pos..-1], options) + end + else + block.call end end end end