From f9b199040c55c26dcd19e4d8077255a24d55b658 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Mon, 21 Nov 2005 20:43:35 +0000 Subject: 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 --- .../lib/action_controller/vendor/html-scanner/html/node.rb | 13 +++++++++++++ .../action_controller/vendor/html-scanner/html/tokenizer.rb | 3 +++ 2 files changed, 16 insertions(+) (limited to 'actionpack/lib/action_controller/vendor') diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index 4f02e2d421..fb961570c4 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -150,6 +150,11 @@ module HTML #:nodoc: end end + if scanner.skip(/!\[CDATA\[/) + scanner.scan_until(/\]\]>/) + return CDATA.new(parent, line, pos, scanner.pre_match) + end + closing = ( scanner.scan(/\//) ? :close : nil ) return Text.new(parent, line, pos, content) unless name = scanner.scan(/[\w:]+/) name.downcase! @@ -256,6 +261,14 @@ module HTML #:nodoc: content == node.content end end + + # A CDATA node is simply a text node with a specialized way of displaying + # itself. + class CDATA < Text + def to_s + "" + end + end # 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 diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb index ce9d3b2800..b950e84628 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb @@ -52,6 +52,9 @@ module HTML #:nodoc: if @scanner.scan(/!--/) # comment tag << @scanner.matched tag << (@scanner.scan_until(/--\s*>/) || @scanner.scan_until(/\Z/)) + elsif @scanner.scan(/!\[CDATA\[/) + tag << @scanner.matched + tag << @scanner.scan_until(/\]\]>/) elsif @scanner.scan(/!/) # doctype tag << @scanner.matched tag << consume_quoted_regions -- cgit v1.2.3