diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index 724df01c..ed23a237 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -23,6 +23,7 @@ module Haml def initialize(options = {}) @options = options @quote_escape = options[:attr_wrapper] == '"' ? """ : "'" + @other_quote_char = options[:attr_wrapper] == '"' ? "'" : '"' @buffer = "" @one_liner_pending = false @tabulation = 0 @@ -172,7 +173,11 @@ module Haml v = v.to_s attr_wrapper = @options[:attr_wrapper] if v.include? attr_wrapper - v = v.gsub(attr_wrapper, @quote_escape) + if v.include? @other_quote_char + v = v.gsub(attr_wrapper, @quote_escape) + else + attr_wrapper = @other_quote_char + end end " #{a}=#{attr_wrapper}#{v}#{attr_wrapper}" end diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index fb4cf87d..638c0a46 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -61,7 +61,8 @@ class EngineTest < Test::Unit::TestCase def test_attr_wrapper assert_equal("

\n

\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*')) - assert_equal("

\n

\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"')) + assert_equal("

\n

\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"')) + assert_equal("

\n

\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"')) assert_equal("\n", render("!!! XML", :attr_wrapper => '"')) end diff --git a/test/haml/results/just_stuff.xhtml b/test/haml/results/just_stuff.xhtml index 7e458470..67e18277 100644 --- a/test/haml/results/just_stuff.xhtml +++ b/test/haml/results/just_stuff.xhtml @@ -6,7 +6,7 @@ -Boo! +Boo!
wow!

Escape