parent
9a586363e9
commit
874d7124af
|
@ -9,7 +9,15 @@ module Oga
|
||||||
# @see [Oga::XML::CharacterNode#to_xml]
|
# @see [Oga::XML::CharacterNode#to_xml]
|
||||||
#
|
#
|
||||||
def to_xml
|
def to_xml
|
||||||
return Entities.encode(super)
|
node = parent
|
||||||
|
root = root_node
|
||||||
|
|
||||||
|
if root.is_a?(Document) and node.is_a?(Element) \
|
||||||
|
and node.name == Lexer::SCRIPT_TAG and root.html?
|
||||||
|
return super
|
||||||
|
else
|
||||||
|
return Entities.encode(super)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end # Text
|
end # Text
|
||||||
end # XML
|
end # XML
|
||||||
|
|
|
@ -26,6 +26,32 @@ describe Oga::XML::Text do
|
||||||
|
|
||||||
node.to_xml.should == '&<>'
|
node.to_xml.should == '&<>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'inside an XML document' do
|
||||||
|
it 'encodes special characters as XML entities' do
|
||||||
|
document = Oga::XML::Document.new
|
||||||
|
script = Oga::XML::Element.new(:name => 'script')
|
||||||
|
text = described_class.new(:text => 'x > y')
|
||||||
|
|
||||||
|
script.children << text
|
||||||
|
document.children << script
|
||||||
|
|
||||||
|
text.to_xml.should == 'x > y'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'inside an HTML <script> element' do
|
||||||
|
it 'does not encode special characters as XML entities' do
|
||||||
|
document = Oga::XML::Document.new(:type => :html)
|
||||||
|
script = Oga::XML::Element.new(:name => 'script')
|
||||||
|
text = described_class.new(:text => 'x > y')
|
||||||
|
|
||||||
|
script.children << text
|
||||||
|
document.children << script
|
||||||
|
|
||||||
|
text.to_xml.should == 'x > y'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#inspect' do
|
describe '#inspect' do
|
||||||
|
|
Loading…
Reference in New Issue