ruby-changes:31614
From: kou <ko1@a...>
Date: Sat, 16 Nov 2013 18:31:31 +0900 (JST)
Subject: [ruby-changes:31614] kou:r43693 (trunk): * lib/rexml/parsers/ultralightparser.rb
kou 2013-11-16 18:31:24 +0900 (Sat, 16 Nov 2013) New Revision: 43693 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43693 Log: * lib/rexml/parsers/ultralightparser.rb (REXML::Parsers::UltraLightParser#parse): Fix wrong :start_doctype position. [Bug #9061] [ruby-dev:47778] Patch by Ippei Obayashi. Thanks!!! * test/rexml/parser/test_ultra_light.rb: Add a test for this case. Added files: trunk/test/rexml/parser/test_ultra_light.rb Modified files: trunk/ChangeLog trunk/lib/rexml/parsers/ultralightparser.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43692) +++ ChangeLog (revision 43693) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Nov 16 18:28:08 2013 Kouhei Sutou <kou@c...> + + * lib/rexml/parsers/ultralightparser.rb + (REXML::Parsers::UltraLightParser#parse): Fix wrong :start_doctype + position. + [Bug #9061] [ruby-dev:47778] + Patch by Ippei Obayashi. Thanks!!! + + * test/rexml/parser/test_ultra_light.rb: Add a test for this case. + Sat Nov 16 02:13:56 2013 Masaya Tarui <tarui@r...> * cont.c : Introduce ensure rollback mechanism. Please see below. Index: lib/rexml/parsers/ultralightparser.rb =================================================================== --- lib/rexml/parsers/ultralightparser.rb (revision 43692) +++ lib/rexml/parsers/ultralightparser.rb (revision 43693) @@ -27,7 +27,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/parsers/ultralightparser.rb#L27 break when :end_doctype context = context[1] - when :start_element, :doctype + when :start_element, :start_doctype context << event event[1,0] = [context] context = event Index: test/rexml/parser/test_ultra_light.rb =================================================================== --- test/rexml/parser/test_ultra_light.rb (revision 0) +++ test/rexml/parser/test_ultra_light.rb (revision 43693) @@ -0,0 +1,67 @@ https://github.com/ruby/ruby/blob/trunk/test/rexml/parser/test_ultra_light.rb#L1 +require "test/unit" +require "rexml/parsers/ultralightparser" + +class TestUltraLightParser < Test::Unit::TestCase + class TestDocumentTypeDeclaration < self + def test_entity_declaration + assert_equal([ + [ + :start_doctype, + :parent, + "root", + "SYSTEM", + "urn:x-test", + nil, + [:entitydecl, "name", "value"] + ], + [:text, "\n"], + [:start_element, :parent, "root", {}], + [:text, "\n"], + ], + parse(<<-INTERNAL_SUBSET)) +<!ENTITY name "value"> + INTERNAL_SUBSET + end + + private + def xml(internal_subset) + <<-XML +<!DOCTYPE root SYSTEM "urn:x-test" [ +#{internal_subset} +]> +<root/> + XML + end + + def parse(internal_subset) + parser = REXML::Parsers::UltraLightParser.new(xml(internal_subset)) + normalize(parser.parse) + end + + def normalize(root) + root.collect do |child| + normalize_child(child) + end + end + + def normalize_child(child) + tag = child.first + case tag + when :start_doctype + normalized_parent = :parent + normalized_doctype = child.dup + normalized_doctype[1] = normalized_parent + normalized_doctype + when :start_element + tag, parent, name, attributes, *children = child + normalized_parent = :parent + normalized_children = children.collect do |sub_child| + normalize_child(sub_child) + end + [tag, normalized_parent, name, attributes, *normalized_children] + else + child + end + end + end +end Property changes on: test/rexml/parser/test_ultra_light.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/