[前][次][番号順一覧][スレッド一覧]

ruby-changes:30146

From: kou <ko1@a...>
Date: Fri, 26 Jul 2013 23:17:37 +0900 (JST)
Subject: [ruby-changes:30146] kou:r42198 (trunk): * lib/rexml/parsers/streamparser.rb

kou	2013-07-26 23:17:24 +0900 (Fri, 26 Jul 2013)

  New Revision: 42198

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42198

  Log:
    * lib/rexml/parsers/streamparser.rb
      (REXML::Parsers::StreamParser#parse): Add "entity" event support to
      listener. [Bug #8689] [ruby-dev:47542]
      Reported by Ippei Obayashi.
    * test/rexml/test_stream.rb (StreamTester#entity): Add a test for
      the above case.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rexml/parsers/streamparser.rb
    trunk/test/rexml/test_stream.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42197)
+++ ChangeLog	(revision 42198)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul 26 23:14:31 2013  Kouhei Sutou  <kou@c...>
+
+	* lib/rexml/parsers/streamparser.rb
+	  (REXML::Parsers::StreamParser#parse): Add "entity" event support to
+	  listener. [Bug #8689] [ruby-dev:47542]
+	  Reported by Ippei Obayashi.
+	* test/rexml/test_stream.rb (StreamTester#entity): Add a test for
+	  the above case.
+
 Fri Jul 26 23:05:27 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (parser_yylex): separate numeric literal from succeeding
Index: lib/rexml/parsers/streamparser.rb
===================================================================
--- lib/rexml/parsers/streamparser.rb	(revision 42197)
+++ lib/rexml/parsers/streamparser.rb	(revision 42198)
@@ -38,6 +38,10 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/parsers/streamparser.rb#L38
             @listener.send( event[0].to_s, *event[1..-1] )
           when :entitydecl, :notationdecl
             @listener.send( event[0].to_s, event[1..-1] )
+          when :externalentity
+            entity_reference = event[1]
+            content = entity_reference.gsub(/\A%|;\z/, "")
+            @listener.entity(content)
           end
         end
       end
Index: test/rexml/test_stream.rb
===================================================================
--- test/rexml/test_stream.rb	(revision 42197)
+++ test/rexml/test_stream.rb	(revision 42198)
@@ -63,6 +63,29 @@ class StreamTester < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/rexml/test_stream.rb#L63
     assert( listener.events[:elementdecl] )
     assert( listener.events[:notationdecl] )
   end
+
+  def test_entity
+    listener = MyListener.new
+    class << listener
+      attr_accessor :entities
+      def entity(content)
+        @entities << content
+      end
+    end
+    listener.entities = []
+
+    source = StringIO.new(<<-XML)
+<!DOCTYPE root [
+<!ENTITY % ISOLat2
+         SYSTEM "http://www.xml.com/iso/isolat2-xml.entities" >
+%ISOLat2;
+]>
+<root/>
+    XML
+    REXML::Document.parse_stream(source, listener)
+
+    assert_equal(["ISOLat2"], listener.entities)
+  end
 end
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]