From ee10d546ff3991860febe8f5bde2a88d3fb09d52 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 7 Jun 2011 19:23:43 -0700 Subject: [PATCH] Fix find_and_preserve with the new #gsub behavior. --- lib/haml/helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb index d928de36..74896f39 100644 --- a/lib/haml/helpers.rb +++ b/lib/haml/helpers.rb @@ -107,7 +107,9 @@ MESSAGE # @yield The block within which to escape newlines def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block) return find_and_preserve(capture_haml(&block), input || tags) if block - input.to_s.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do + re = /<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im + input.to_s.gsub(re) do |s| + s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible "<#{$1}#{$2}>#{preserve($3)}" end end