Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/builder/xmlbase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def explicit_nil_handling?
def tag!(sym, *args, &block)
text = nil
attrs = nil
escape_text = true
sym = "#{sym}:#{args.shift}" if args.first.kind_of?(::Symbol)
sym = sym.to_sym unless sym.class == ::Symbol
args.each do |arg|
Expand All @@ -51,6 +52,8 @@ def tag!(sym, *args, &block)
when nil
attrs ||= {}
attrs.merge!({:nil => true}) if explicit_nil_handling?
when true, false
escape_text = arg
else
text ||= ''
text << arg.to_s
Expand Down Expand Up @@ -78,7 +81,11 @@ def tag!(sym, *args, &block)
else
_indent
_start_tag(sym, attrs)
text! text
if escape_text
text! text
else
self << text
end
_end_tag(sym)
_newline
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_markupbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def test_non_escaping
assert_equal %{<div ns:xml="&xml;"><h&i><em>H&amp;R Block</em></div>}, @xml.target!
end

def test_dont_escape
@xml.div({"id"=>2}, false, 'H&amp;R Block')
assert_equal %{<div id="2">H&amp;R Block</div>}, @xml.target!
end

def test_return_value
str = @xml.x("men")
assert_equal @xml.target!, str
Expand Down