diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-23 13:35:11 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-23 13:35:11 +0000 |
commit | 93402a2f179abbb89bca9337b85a420596cc7753 (patch) | |
tree | 71e0eec4b90f0f355f3dc4f83f774736c8b3191a /lib/rss/xmlscanner.rb | |
parent | 4b87fa9de2b62d553f56671fef792a357d0996f7 (diff) |
* lib/rss/parser.rb: added entity handling type predicate.
* lib/rss/rexmlparser.rb: ditto.
* lib/rss/xmlparser.rb: ditto.
* lib/rss/xmlscanner.rb: ditto.
* lib/rss/xmlscanner.rb: more robust entity handling.
* test/rss/test_parser.rb: added an entity handling test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss/xmlscanner.rb')
-rw-r--r-- | lib/rss/xmlscanner.rb | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/rss/xmlscanner.rb b/lib/rss/xmlscanner.rb index c5a11bad18..61b9fa6bf4 100644 --- a/lib/rss/xmlscanner.rb +++ b/lib/rss/xmlscanner.rb @@ -1,19 +1,29 @@ require 'xmlscan/scanner' +require 'stringio' module RSS class XMLScanParser < BaseParser - private - def listener - XMLScanListener + class << self + def listener + XMLScanListener + end end - + + private def _parse begin - XMLScan::XMLScanner.new(@listener).parse(@rss) + if @rss.is_a?(String) + input = StringIO.new(@rss) + else + input = @rss + end + scanner = XMLScan::XMLScanner.new(@listener) + scanner.parse(input) rescue XMLScan::Error => e - raise NotWellFormedError.new(e.lineno){e.message} + lineno = e.lineno || scanner.lineno || input.lineno + raise NotWellFormedError.new(lineno){e.message} end end @@ -57,7 +67,7 @@ module RSS end def on_entityref(ref) - text(ENTITIES[ref]) + text(entity(ref)) end def on_charref(code) @@ -79,7 +89,7 @@ module RSS end def on_attr_entityref(ref) - @current_attr << ENTITIES[ref] + @current_attr << entity(ref) end def on_attr_charref(code) @@ -97,6 +107,15 @@ module RSS tag_end(name) end + private + def entity(ref) + ent = ENTITIES[ref] + if ent + ent + else + wellformed_error("undefined entity: #{ref}") + end + end end end |