From fb5ab2675fd4de99bec6b3f0594da041d58eb8bb Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 20 May 2011 12:54:52 -0700 Subject: [PATCH 1/3] Fix html2haml. --- doc-src/HAML_CHANGELOG.md | 2 ++ lib/haml/exec.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index c309c903..612c9588 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -10,6 +10,8 @@ * Don't throw errors when text is nested within comments. +* Fix html2haml. + ## 3.1.1 * Update the vendored Sass to version 3.1.0. 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. From fc5a5cb21de15a7c2fde83d4e06a021b2d86c4f1 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 7 Jun 2011 19:12:06 -0700 Subject: [PATCH 2/3] Don't destructively modify SafeBuffers. Closes gh-399 Closes gh-400 --- doc-src/HAML_CHANGELOG.md | 2 ++ lib/haml/compiler.rb | 2 +- lib/haml/helpers.rb | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 612c9588..cb827b00 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -12,6 +12,8 @@ * 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/helpers.rb b/lib/haml/helpers.rb index ec527cde..d928de36 100644 --- a/lib/haml/helpers.rb +++ b/lib/haml/helpers.rb @@ -170,10 +170,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}
  • " From ee10d546ff3991860febe8f5bde2a88d3fb09d52 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 7 Jun 2011 19:23:43 -0700 Subject: [PATCH 3/3] 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