Don't convert entities in script/style elements

In HTML the text of a script/style tag should be left untouched, no
entities must be converted. Doing so would break Javascript such as the
following:

    foo&&bar;

Such code is often the result of minifiers doing their dirty business.
This commit is contained in:
Yorick Peterse committed 2015-04-08 14:32:09 +02:00
1 parent 6a1010c287
commit 4bdc8a3fdc
2 files changed
+53 -7

No files matched your search

+21 -7
View File
@@ -26,7 +26,7 @@ module Oga
# @return [String]
#
def text
unless @decoded
if decode_entities?
@text = EntityDecoder.try_decode(@text, html?)
@decoded = true
end
@@ -38,15 +38,29 @@ module Oga
# @see [Oga::XML::CharacterNode#to_xml]
#
def to_xml
node = parent
if node.is_a?(Element) and html? \
and Lexer::LITERAL_HTML_ELEMENTS.include?(node.name)
return super
end
return super if inside_literal_html?
return Entities.encode(super)
end
private
##
# @return [TrueClass|FalseClass]
#
def decode_entities?
return !@decoded && !inside_literal_html?
end
##
# @return [TrueClass|FalseClass]
#
def inside_literal_html?
node = parent
return node.is_a?(Element) && html? &&
Lexer::LITERAL_HTML_ELEMENTS.include?(node.name)
end
end # Text
end # XML
end # Oga