diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 00:51:31 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 00:51:31 +0000 |
commit | 88dd1e4c993e661b0d52c40d0eff567b00bf6ffd (patch) | |
tree | e8298605f2f0e29f2ec2befeda793b46194e4ddd /lib/rss/xmlscanner.rb | |
parent | e85f8c782958c0a3e6ea296401a08d5fe9f8e550 (diff) |
* lib/rss, test/rss: backported from trunk. (2005-11-16 - now)
* 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/branches/ruby_1_8@10295 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 |