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 | 0667cd0b6378e413c28277a43442b6554c7b53e1 (patch) | |
| tree | e8298605f2f0e29f2ec2befeda793b46194e4ddd /lib/rss/xmlscanner.rb | |
| parent | 9dc733281997c4c6668dfd02561c0d9621988759 (diff) | |
| download | ruby-0667cd0b6378e413c28277a43442b6554c7b53e1.tar.gz ruby-0667cd0b6378e413c28277a43442b6554c7b53e1.tar.xz ruby-0667cd0b6378e413c28277a43442b6554c7b53e1.zip | |
* 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: http://svn.ruby-lang.org/repos/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 c5a11bad1..61b9fa6bf 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 |
