diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-16 09:31:24 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-16 09:31:24 +0000 |
commit | a66a9fbb10608bc81fb466d1ad57805ce1134b7e (patch) | |
tree | 6027f00f3e13736d48e028ac25ca964e2bf2efe0 /test/rexml | |
parent | bc3db2a512b3aba51a49de29dd5165d619fe09a1 (diff) | |
download | ruby-a66a9fbb10608bc81fb466d1ad57805ce1134b7e.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml')
-rw-r--r-- | test/rexml/parser/test_ultra_light.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/rexml/parser/test_ultra_light.rb b/test/rexml/parser/test_ultra_light.rb new file mode 100644 index 0000000000..852aa5bf6d --- /dev/null +++ b/test/rexml/parser/test_ultra_light.rb @@ -0,0 +1,67 @@ +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 |