diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index c309c903..cb827b00 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -10,6 +10,10 @@ * Don't throw errors when text is nested within comments. +* Fix html2haml. + +* Fix an issue where destructive modification was sometimes performed on Rails SafeBuffers. + ## 3.1.1 * Update the vendored Sass to version 3.1.0. diff --git a/lib/haml/compiler.rb b/lib/haml/compiler.rb index c742a40b..0cfc4179 100644 --- a/lib/haml/compiler.rb +++ b/lib/haml/compiler.rb @@ -379,7 +379,7 @@ END value = Haml::Helpers.preserve(escaped) if escape_attrs # We want to decide whether or not to escape quotes - value.gsub!('"', '"') + value = value.gsub('"', '"') this_attr_wrapper = attr_wrapper if value.include? attr_wrapper if value.include? other_quote_char diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 81eea019..fc8b6217 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -9,7 +9,7 @@ module Haml # @param args [Array] The command-line arguments def initialize(args) @args = args - @options = {} + @options = {:for_engine => {}} end # Parses the command-line arguments and runs the executable. diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb index ec527cde..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 @@ -170,10 +172,10 @@ MESSAGE result = capture_haml(i, &block) if result.count("\n") > 1 - result.gsub!("\n", "\n ") + result = result.gsub("\n", "\n ") result = "\n #{result.strip}\n" else - result.strip! + result = result.strip end "
  • #{result}
  • "