summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--lib/rexml/parsers/ultralightparser.rb2
-rw-r--r--test/rexml/parser/test_ultra_light.rb67
3 files changed, 78 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 815b03e8bd..f31c2f01ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sat Nov 16 18:28:08 2013 Kouhei Sutou <kou@cozmixng.org>
+
+ * 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@ruby-lang.org>
* cont.c : Introduce ensure rollback mechanism. Please see below.
diff --git a/lib/rexml/parsers/ultralightparser.rb b/lib/rexml/parsers/ultralightparser.rb
index 7dd8172802..4e2d7a81cf 100644
--- a/lib/rexml/parsers/ultralightparser.rb
+++ b/lib/rexml/parsers/ultralightparser.rb
@@ -27,7 +27,7 @@ module REXML
break
when :end_doctype
context = context[1]
- when :start_element, :doctype
+ when :start_element, :start_doctype
context << event
event[1,0] = [context]
context = event
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