Fix for quote character bug (1.5dev)

git-svn-id: svn://hamptoncatlin.com/haml/branches/1.5dev@206 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-12-10 21:56:05 +00:00
parent 6914f275f3
commit d9f27b263f
3 changed files with 9 additions and 3 deletions

View File

@ -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
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

View File

@ -61,7 +61,8 @@ class EngineTest < Test::Unit::TestCase
def test_attr_wrapper
assert_equal("<p strange=*attrs*>\n</p>\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*'))
assert_equal("<p escaped=\"quo&quot;te\">\n</p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
assert_equal("<p escaped='quo\"te'>\n</p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
assert_equal("<p escaped=\"q'uo&quot;te\">\n</p>\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"'))
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"'))
end

View File

@ -6,7 +6,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<strong apos='Foo&apos;s bar!'>Boo!</strong>
<strong apos="Foo's bar!">Boo!</strong>
<div class='render'><em>wow!</em></div>
<p>
Escape