提交 f9b19904 编写于 作者: J Jamis Buck

Update html-scanner to handle CDATA sections better. Closes #2970. [Jamis Buck]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3153 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 f1a184fe
*SVN* *SVN*
* Update html-scanner to handle CDATA sections better. Closes #2970. [Jamis Buck]
* Don't put flash in session if sessions are disabled. [Jeremy Kemper] * Don't put flash in session if sessions are disabled. [Jeremy Kemper]
* Strip out trailing &_= for raw post bodies. Closes #2868. [Sam Stephenson] * Strip out trailing &_= for raw post bodies. Closes #2868. [Sam Stephenson]
......
...@@ -150,6 +150,11 @@ def parse(parent, line, pos, content, strict=true) ...@@ -150,6 +150,11 @@ def parse(parent, line, pos, content, strict=true)
end end
end end
if scanner.skip(/!\[CDATA\[/)
scanner.scan_until(/\]\]>/)
return CDATA.new(parent, line, pos, scanner.pre_match)
end
closing = ( scanner.scan(/\//) ? :close : nil ) closing = ( scanner.scan(/\//) ? :close : nil )
return Text.new(parent, line, pos, content) unless name = scanner.scan(/[\w:]+/) return Text.new(parent, line, pos, content) unless name = scanner.scan(/[\w:]+/)
name.downcase! name.downcase!
...@@ -256,6 +261,14 @@ def ==(node) ...@@ -256,6 +261,14 @@ def ==(node)
content == node.content content == node.content
end end
end end
# A CDATA node is simply a text node with a specialized way of displaying
# itself.
class CDATA < Text
def to_s
"<![CDATA[#{super}]>"
end
end
# A Tag is any node that represents markup. It may be an opening tag, a # A Tag is any node that represents markup. It may be an opening tag, a
# closing tag, or a self-closing tag. It has a name, and may have a hash of # closing tag, or a self-closing tag. It has a name, and may have a hash of
......
...@@ -52,6 +52,9 @@ def scan_tag ...@@ -52,6 +52,9 @@ def scan_tag
if @scanner.scan(/!--/) # comment if @scanner.scan(/!--/) # comment
tag << @scanner.matched tag << @scanner.matched
tag << (@scanner.scan_until(/--\s*>/) || @scanner.scan_until(/\Z/)) tag << (@scanner.scan_until(/--\s*>/) || @scanner.scan_until(/\Z/))
elsif @scanner.scan(/!\[CDATA\[/)
tag << @scanner.matched
tag << @scanner.scan_until(/\]\]>/)
elsif @scanner.scan(/!/) # doctype elsif @scanner.scan(/!/) # doctype
tag << @scanner.matched tag << @scanner.matched
tag << consume_quoted_regions tag << consume_quoted_regions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册