libxml-ruby 5.0.6 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{HISTORY → CHANGELOG.md} +875 -930
- data/LICENSE +20 -20
- data/README.md +67 -0
- data/Rakefile +13 -34
- data/ext/libxml/extconf.rb +34 -20
- data/ext/libxml/libxml.c +2 -14
- data/ext/libxml/ruby_libxml.h +1 -1
- data/ext/libxml/ruby_xml_attr.c +27 -22
- data/ext/libxml/ruby_xml_attr.h +1 -0
- data/ext/libxml/ruby_xml_attr_decl.c +19 -12
- data/ext/libxml/ruby_xml_attributes.c +18 -9
- data/ext/libxml/ruby_xml_document.c +111 -98
- data/ext/libxml/ruby_xml_document.h +1 -0
- data/ext/libxml/ruby_xml_dtd.c +49 -19
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_html_parser.c +1 -1
- data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
- data/ext/libxml/ruby_xml_html_parser_context.h +1 -0
- data/ext/libxml/ruby_xml_input_cbg.c +45 -17
- data/ext/libxml/ruby_xml_io.c +3 -1
- data/ext/libxml/ruby_xml_namespace.c +20 -12
- data/ext/libxml/ruby_xml_namespace.h +1 -0
- data/ext/libxml/ruby_xml_namespaces.c +40 -20
- data/ext/libxml/ruby_xml_node.c +71 -32
- data/ext/libxml/ruby_xml_node.h +2 -0
- data/ext/libxml/ruby_xml_parser.c +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +54 -47
- data/ext/libxml/ruby_xml_parser_context.h +1 -0
- data/ext/libxml/ruby_xml_reader.c +25 -15
- data/ext/libxml/ruby_xml_registry.c +31 -0
- data/ext/libxml/ruby_xml_registry.h +22 -0
- data/ext/libxml/ruby_xml_relaxng.c +21 -5
- data/ext/libxml/ruby_xml_relaxng.h +1 -0
- data/ext/libxml/ruby_xml_sax_parser.c +1 -1
- data/ext/libxml/ruby_xml_schema.c +18 -11
- data/ext/libxml/ruby_xml_schema.h +1 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
- data/ext/libxml/ruby_xml_schema_element.c +8 -8
- data/ext/libxml/ruby_xml_schema_facet.c +7 -7
- data/ext/libxml/ruby_xml_schema_type.c +12 -19
- data/ext/libxml/ruby_xml_version.h +4 -4
- data/ext/libxml/ruby_xml_writer.c +18 -6
- data/ext/libxml/ruby_xml_xpath.c +2 -2
- data/ext/libxml/ruby_xml_xpath.h +1 -1
- data/ext/libxml/ruby_xml_xpath_context.c +72 -26
- data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
- data/ext/libxml/ruby_xml_xpath_expression.h +1 -0
- data/ext/libxml/ruby_xml_xpath_object.c +69 -54
- data/ext/libxml/ruby_xml_xpath_object.h +3 -1
- data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
- data/lib/libxml/document.rb +0 -29
- data/lib/libxml/error.rb +30 -3
- data/lib/libxml/html_parser.rb +0 -16
- data/lib/libxml/node.rb +1 -3
- data/lib/libxml/parser.rb +0 -8
- data/lib/libxml/schema/attribute.rb +27 -19
- data/lib/libxml/schema/element.rb +20 -0
- data/lib/libxml/schema/type.rb +44 -21
- data/lib/libxml/schema.rb +47 -47
- data/lib/libxml-ruby.rb +30 -30
- data/libxml-ruby.gemspec +12 -16
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/test_attr.rb +179 -180
- data/test/test_attr_decl.rb +131 -131
- data/test/test_attributes.rb +135 -135
- data/test/test_canonicalize.rb +122 -120
- data/test/test_document.rb +2 -4
- data/test/test_dtd.rb +12 -4
- data/test/test_encoding_sax.rb +114 -114
- data/test/test_error.rb +1 -1
- data/test/test_html_parser.rb +6 -2
- data/test/test_html_parser_context.rb +22 -22
- data/test/test_input_callbacks.rb +36 -0
- data/test/test_namespace.rb +1 -1
- data/test/test_namespaces.rb +200 -200
- data/test/test_node.rb +16 -0
- data/test/test_node_cdata.rb +50 -50
- data/test/test_node_comment.rb +32 -32
- data/test/test_node_copy.rb +40 -40
- data/test/test_node_edit.rb +176 -158
- data/test/test_node_pi.rb +37 -37
- data/test/test_node_text.rb +69 -69
- data/test/test_node_xlink.rb +28 -28
- data/test/test_parser.rb +5 -41
- data/test/test_parser_context.rb +198 -198
- data/test/test_properties.rb +38 -38
- data/test/test_reader.rb +55 -6
- data/test/test_relaxng.rb +59 -53
- data/test/test_sax_parser.rb +345 -345
- data/test/test_schema.rb +28 -0
- data/test/test_traversal.rb +152 -152
- data/test/test_writer.rb +0 -31
- data/test/test_xinclude.rb +20 -20
- data/test/test_xml.rb +3 -7
- data/test/test_xpath.rb +244 -244
- data/test/test_xpath_context.rb +87 -87
- data/test/test_xpath_expression.rb +37 -37
- metadata +32 -25
- data/README.rdoc +0 -208
- data/ext/libxml/extconf.h +0 -4
- data/ext/libxml/ruby_xml_cbg.c +0 -85
- data/lib/libxml/hpricot.rb +0 -78
- data/lib/libxml.rb +0 -5
- data/lib/xml/libxml.rb +0 -10
- data/lib/xml.rb +0 -14
- data/script/benchmark/depixelate +0 -634
- data/script/benchmark/hamlet.xml +0 -9055
- data/script/benchmark/parsecount +0 -170
- data/script/benchmark/sock_entries.xml +0 -507
- data/script/benchmark/throughput +0 -41
- data/script/test +0 -6
- data/test/test_deprecated_require.rb +0 -12
data/test/test_canonicalize.rb
CHANGED
|
@@ -1,120 +1,122 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative './test_helper'
|
|
3
|
-
|
|
4
|
-
class TestCanonicalize < Minitest::Test
|
|
5
|
-
def path(file)
|
|
6
|
-
File.join(File.dirname(__FILE__), file)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
# (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
|
|
10
|
-
# http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
|
|
11
|
-
def test_canonicalize_with_w3c_c14n_3_1
|
|
12
|
-
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
|
|
13
|
-
|
|
14
|
-
# With Comments
|
|
15
|
-
expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
|
|
16
|
-
assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
|
|
17
|
-
|
|
18
|
-
# Without Comments
|
|
19
|
-
expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-1'))
|
|
20
|
-
assert_equal(expected_without_comments, given_doc.canonicalize)
|
|
21
|
-
assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
|
|
22
|
-
|
|
23
|
-
# Without Comments (XML_C14N_1_1)
|
|
24
|
-
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
|
|
25
|
-
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
26
|
-
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
expected
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
mode
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expected
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
mode
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expected
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
mode
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
#
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
assert_equal(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require_relative './test_helper'
|
|
3
|
+
|
|
4
|
+
class TestCanonicalize < Minitest::Test
|
|
5
|
+
def path(file)
|
|
6
|
+
File.join(File.dirname(__FILE__), file)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
|
|
10
|
+
# http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
|
|
11
|
+
def test_canonicalize_with_w3c_c14n_3_1
|
|
12
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
|
|
13
|
+
|
|
14
|
+
# With Comments
|
|
15
|
+
expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
|
|
16
|
+
assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
|
|
17
|
+
|
|
18
|
+
# Without Comments
|
|
19
|
+
expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-1'))
|
|
20
|
+
assert_equal(expected_without_comments, given_doc.canonicalize)
|
|
21
|
+
assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
|
|
22
|
+
|
|
23
|
+
# Without Comments (XML_C14N_1_1)
|
|
24
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
|
|
25
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
26
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# (www.w3.org) 3.2 Whitespace in Document Content
|
|
30
|
+
# http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
|
|
31
|
+
def test_canonicalize_with_w3c_c14n_3_2
|
|
32
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
|
|
33
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-2'))
|
|
34
|
+
assert_equal(expected, given_doc.canonicalize)
|
|
35
|
+
|
|
36
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
|
|
37
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
38
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# (www.w3.org) 3.3 Start and End Tags
|
|
42
|
+
# http://www.w3.org/TR/xml-c14n#Example-SETags
|
|
43
|
+
# (2012-02-20) Test failing due to missing 'attr' in 'e9' node.
|
|
44
|
+
# - Embedded DTD not parsed out of XML, therefore default attributes are
|
|
45
|
+
# not applied to canonicalization.
|
|
46
|
+
def test_canonicalize_with_w3c_c14n_3_3
|
|
47
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
|
|
48
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-3'))
|
|
49
|
+
assert_equal(expected, given_doc.canonicalize)
|
|
50
|
+
|
|
51
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
|
|
52
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
53
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# (www.w3.org) 3.4 Character Modifications and Character References
|
|
57
|
+
# http://www.w3.org/TR/xml-c14n#Example-Chars
|
|
58
|
+
def test_canonicalize_with_w3c_c14n_3_4
|
|
59
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
|
|
60
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-4'))
|
|
61
|
+
assert_equal(expected, given_doc.canonicalize)
|
|
62
|
+
|
|
63
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
|
|
64
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
65
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# (www.w3.org) 3.5 Entity References
|
|
69
|
+
# http://www.w3.org/TR/xml-c14n#Example-Entities
|
|
70
|
+
def test_canonicalize_with_w3c_c14n_3_5
|
|
71
|
+
# NOENT resolves entity references, DTDLOAD loads the external entity
|
|
72
|
+
options = LibXML::XML::Parser::Options::NOENT | LibXML::XML::Parser::Options::DTDLOAD
|
|
73
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'), options: options)
|
|
74
|
+
|
|
75
|
+
# With Comments
|
|
76
|
+
expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
|
|
77
|
+
assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
|
|
78
|
+
|
|
79
|
+
# Without Comments
|
|
80
|
+
expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-5'))
|
|
81
|
+
assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
|
|
82
|
+
|
|
83
|
+
# Without Comments (XML_C14N_1_1)
|
|
84
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
|
|
85
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
86
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# (www.w3.org) 3.6 UTF-8 Encoding
|
|
90
|
+
# http://www.w3.org/TR/xml-c14n#Example-UTF8
|
|
91
|
+
def test_canonicalize_with_w3c_c14n_3_6
|
|
92
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
|
|
93
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
|
|
94
|
+
assert_equal(expected, given_doc.canonicalize)
|
|
95
|
+
|
|
96
|
+
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
|
|
97
|
+
mode = LibXML::XML::Document::XML_C14N_1_1
|
|
98
|
+
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# (www.w3.org) 3.7 Document Subsets
|
|
102
|
+
# http://www.w3.org/TR/xml-c14n#Example-DocSubsets
|
|
103
|
+
def test_canonicalize_with_w3c_c14n_3_7
|
|
104
|
+
# Parse with DTDATTR and DTDLOAD so default attributes and ID types
|
|
105
|
+
# from the internal DTD subset are materialized
|
|
106
|
+
options = LibXML::XML::Parser::Options::DTDATTR | LibXML::XML::Parser::Options::DTDLOAD
|
|
107
|
+
given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'),
|
|
108
|
+
options: options)
|
|
109
|
+
expected = IO.read(self.path('c14n/result/without-comments/example-7'))
|
|
110
|
+
|
|
111
|
+
ctx = given_doc.context
|
|
112
|
+
ctx.register_namespace('ietf', 'http://www.ietf.org')
|
|
113
|
+
|
|
114
|
+
# W3C C14N spec example 3.7 XPath expression for document subsets
|
|
115
|
+
subdoc_nodes = ctx.find(
|
|
116
|
+
"(//. | //@* | //namespace::*)" \
|
|
117
|
+
"[self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::e2))" \
|
|
118
|
+
" or count(id('E3')|ancestor-or-self::node()) = count(ancestor-or-self::node())]")
|
|
119
|
+
|
|
120
|
+
assert_equal(expected, given_doc.canonicalize(:nodes => subdoc_nodes))
|
|
121
|
+
end
|
|
122
|
+
end
|
data/test/test_document.rb
CHANGED
|
@@ -43,14 +43,12 @@ class TestDocument < Minitest::Test
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
10.upto(20) do |i|
|
|
46
|
-
|
|
47
|
-
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
|
|
46
|
+
assert_equal(i, @doc.compression = i)
|
|
48
47
|
assert_equal(9, @doc.compression)
|
|
49
48
|
end
|
|
50
49
|
|
|
51
50
|
-1.downto(-10) do |i|
|
|
52
|
-
|
|
53
|
-
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
|
|
51
|
+
@doc.compression = i
|
|
54
52
|
assert_equal(0, @doc.compression)
|
|
55
53
|
end
|
|
56
54
|
end
|
data/test/test_dtd.rb
CHANGED
|
@@ -44,6 +44,16 @@ class TestDtd < Minitest::Test
|
|
|
44
44
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def test_internal_subset_nil_ids
|
|
48
|
+
doc = LibXML::XML::Document.new
|
|
49
|
+
doc.root = LibXML::XML::Node.new('test')
|
|
50
|
+
dtd = LibXML::XML::Dtd.new(nil, nil, 'test', doc, true)
|
|
51
|
+
assert_equal('test', dtd.name)
|
|
52
|
+
assert_nil(dtd.external_id)
|
|
53
|
+
assert_nil(dtd.uri)
|
|
54
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE test>\n<test/>\n", doc.to_s)
|
|
55
|
+
end
|
|
56
|
+
|
|
47
57
|
def test_external_subset
|
|
48
58
|
xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil)
|
|
49
59
|
assert xhtml_dtd.name.nil?
|
|
@@ -112,14 +122,12 @@ class TestDtd < Minitest::Test
|
|
|
112
122
|
errors.clear
|
|
113
123
|
LibXML::XML::Parser.string(xml, options: LibXML::XML::Parser::Options::DTDLOAD).parse
|
|
114
124
|
assert_equal(1, errors.length)
|
|
115
|
-
|
|
116
|
-
errors[0].to_s)
|
|
125
|
+
assert_match(/Warning: failed to load.*test\.dtd/, errors[0].to_s)
|
|
117
126
|
|
|
118
127
|
errors = Array.new
|
|
119
128
|
LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
|
|
120
129
|
assert_equal(1, errors.length)
|
|
121
|
-
|
|
122
|
-
errors[0].to_s)
|
|
130
|
+
assert_match(/Warning: failed to load.*test\.dtd/, errors[0].to_s)
|
|
123
131
|
ensure
|
|
124
132
|
LibXML::XML::Error.reset_handler
|
|
125
133
|
end
|
data/test/test_encoding_sax.rb
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative './test_helper'
|
|
3
|
-
|
|
4
|
-
class SaxEncodingCallbacks
|
|
5
|
-
attr_reader :encoding
|
|
6
|
-
attr_accessor :assertions
|
|
7
|
-
include Minitest::Assertions
|
|
8
|
-
|
|
9
|
-
def initialize
|
|
10
|
-
@assertions = 0
|
|
11
|
-
@encoding = Encoding::UTF_8
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Called for a CDATA block event.
|
|
15
|
-
def on_cdata_block(cdata)
|
|
16
|
-
assert_equal(self.encoding, cdata.encoding)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Called for a characters event.
|
|
20
|
-
def on_characters(chars)
|
|
21
|
-
assert_equal(self.encoding, chars.encoding)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Called for a comment event.
|
|
25
|
-
def on_comment(msg)
|
|
26
|
-
assert_equal(self.encoding, msg.encoding)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Called for a end document event.
|
|
30
|
-
def on_end_document
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Called for a end element event.
|
|
34
|
-
def on_end_element_ns(name, prefix, uri)
|
|
35
|
-
assert_equal(self.encoding, name.encoding)
|
|
36
|
-
assert_equal(self.encoding, prefix.encoding) if prefix
|
|
37
|
-
assert_equal(self.encoding, uri.encoding) if uri
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Called for parser errors.
|
|
41
|
-
def on_error(msg)
|
|
42
|
-
assert_equal(self.encoding, msg.encoding)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Called for an external subset event.
|
|
46
|
-
def on_external_subset(name, external_id, system_id)
|
|
47
|
-
assert_equal(self.encoding, name.encoding)
|
|
48
|
-
assert_equal(self.encoding, external_id.encoding)
|
|
49
|
-
assert_equal(self.encoding, system_id.encoding)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Called for an external subset notification event.
|
|
53
|
-
def on_has_external_subset
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Called for an internal subset notification event.
|
|
57
|
-
def on_has_internal_subset
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Called for an internal subset event.
|
|
61
|
-
def on_internal_subset(name, external_id, system_id)
|
|
62
|
-
assert_equal(self.encoding, name.encoding)
|
|
63
|
-
assert_equal(self.encoding, external_id.encoding)
|
|
64
|
-
assert_equal(self.encoding, system_id.encoding)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Called for 'is standalone' event.
|
|
68
|
-
def on_is_standalone
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Called for an processing instruction event.
|
|
72
|
-
def on_processing_instruction(target, data)
|
|
73
|
-
assert_equal(self.encoding, target.encoding)
|
|
74
|
-
assert_equal(self.encoding, data.encoding)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Called for a reference event.
|
|
78
|
-
def on_reference(name)
|
|
79
|
-
assert_equal(self.encoding, name.encoding)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Called for a start document event.
|
|
83
|
-
def on_start_document
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Called for a start element event.
|
|
87
|
-
def on_start_element_ns(name, attributes, prefix, uri, namespaces)
|
|
88
|
-
assert_equal(self.encoding, name.encoding) if name
|
|
89
|
-
assert_equal(self.encoding, prefix.encoding) if prefix
|
|
90
|
-
assert_equal(self.encoding, uri.encoding) if uri
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
class TestEncodingSax < Minitest::Test
|
|
95
|
-
def setup
|
|
96
|
-
Encoding.default_internal = nil
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def file_for_encoding(encoding)
|
|
100
|
-
file_name = "model/bands.#{encoding.name.downcase}.xml"
|
|
101
|
-
File.join(File.dirname(__FILE__), file_name)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_encoding_iso_8859_1
|
|
105
|
-
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
|
|
106
|
-
parser.callbacks = SaxEncodingCallbacks.new
|
|
107
|
-
parser.parse
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_encoding_utf8
|
|
111
|
-
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
|
|
112
|
-
parser.callbacks = SaxEncodingCallbacks.new
|
|
113
|
-
parser.parse
|
|
114
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require_relative './test_helper'
|
|
3
|
+
|
|
4
|
+
class SaxEncodingCallbacks
|
|
5
|
+
attr_reader :encoding
|
|
6
|
+
attr_accessor :assertions
|
|
7
|
+
include Minitest::Assertions
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@assertions = 0
|
|
11
|
+
@encoding = Encoding::UTF_8
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Called for a CDATA block event.
|
|
15
|
+
def on_cdata_block(cdata)
|
|
16
|
+
assert_equal(self.encoding, cdata.encoding)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Called for a characters event.
|
|
20
|
+
def on_characters(chars)
|
|
21
|
+
assert_equal(self.encoding, chars.encoding)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Called for a comment event.
|
|
25
|
+
def on_comment(msg)
|
|
26
|
+
assert_equal(self.encoding, msg.encoding)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Called for a end document event.
|
|
30
|
+
def on_end_document
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Called for a end element event.
|
|
34
|
+
def on_end_element_ns(name, prefix, uri)
|
|
35
|
+
assert_equal(self.encoding, name.encoding)
|
|
36
|
+
assert_equal(self.encoding, prefix.encoding) if prefix
|
|
37
|
+
assert_equal(self.encoding, uri.encoding) if uri
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Called for parser errors.
|
|
41
|
+
def on_error(msg)
|
|
42
|
+
assert_equal(self.encoding, msg.encoding)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Called for an external subset event.
|
|
46
|
+
def on_external_subset(name, external_id, system_id)
|
|
47
|
+
assert_equal(self.encoding, name.encoding)
|
|
48
|
+
assert_equal(self.encoding, external_id.encoding)
|
|
49
|
+
assert_equal(self.encoding, system_id.encoding)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Called for an external subset notification event.
|
|
53
|
+
def on_has_external_subset
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Called for an internal subset notification event.
|
|
57
|
+
def on_has_internal_subset
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Called for an internal subset event.
|
|
61
|
+
def on_internal_subset(name, external_id, system_id)
|
|
62
|
+
assert_equal(self.encoding, name.encoding)
|
|
63
|
+
assert_equal(self.encoding, external_id.encoding)
|
|
64
|
+
assert_equal(self.encoding, system_id.encoding)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Called for 'is standalone' event.
|
|
68
|
+
def on_is_standalone
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Called for an processing instruction event.
|
|
72
|
+
def on_processing_instruction(target, data)
|
|
73
|
+
assert_equal(self.encoding, target.encoding)
|
|
74
|
+
assert_equal(self.encoding, data.encoding)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Called for a reference event.
|
|
78
|
+
def on_reference(name)
|
|
79
|
+
assert_equal(self.encoding, name.encoding)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Called for a start document event.
|
|
83
|
+
def on_start_document
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Called for a start element event.
|
|
87
|
+
def on_start_element_ns(name, attributes, prefix, uri, namespaces)
|
|
88
|
+
assert_equal(self.encoding, name.encoding) if name
|
|
89
|
+
assert_equal(self.encoding, prefix.encoding) if prefix
|
|
90
|
+
assert_equal(self.encoding, uri.encoding) if uri
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class TestEncodingSax < Minitest::Test
|
|
95
|
+
def setup
|
|
96
|
+
Encoding.default_internal = nil
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def file_for_encoding(encoding)
|
|
100
|
+
file_name = "model/bands.#{encoding.name.downcase}.xml"
|
|
101
|
+
File.join(File.dirname(__FILE__), file_name)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_encoding_iso_8859_1
|
|
105
|
+
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
|
|
106
|
+
parser.callbacks = SaxEncodingCallbacks.new
|
|
107
|
+
parser.parse
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_encoding_utf8
|
|
111
|
+
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
|
|
112
|
+
parser.callbacks = SaxEncodingCallbacks.new
|
|
113
|
+
parser.parse
|
|
114
|
+
end
|
|
115
115
|
end
|
data/test/test_error.rb
CHANGED
|
@@ -154,7 +154,7 @@ class TestError < Minitest::Test
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
def test_double_parse_register_handler
|
|
157
|
-
LibXML::XML::
|
|
157
|
+
LibXML::XML::Error.set_handler {|msg| nil }
|
|
158
158
|
parser = LibXML::XML::Parser.string("<test>something</test>")
|
|
159
159
|
parser.parse
|
|
160
160
|
|
data/test/test_html_parser.rb
CHANGED
|
@@ -21,7 +21,7 @@ class HTMLParserTest < Minitest::Test
|
|
|
21
21
|
LibXML::XML::HTMLParser.file('i_dont_exist.xml')
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
assert_match(/Warning: failed to load.*i_dont_exist\.xml/, error.to_s)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def test_nil_file
|
|
@@ -141,7 +141,11 @@ class HTMLParserTest < Minitest::Test
|
|
|
141
141
|
html = "hello world"
|
|
142
142
|
parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOIMPLIED)
|
|
143
143
|
doc = parser.parse
|
|
144
|
-
|
|
144
|
+
if Gem::Version.new(LibXML::XML::LIBXML_VERSION) >= Gem::Version.new("2.14")
|
|
145
|
+
assert_nil(doc.root)
|
|
146
|
+
else
|
|
147
|
+
assert_equal("<p>#{html}</p>", doc.root.to_s)
|
|
148
|
+
end
|
|
145
149
|
end
|
|
146
150
|
|
|
147
151
|
def test_comment
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require_relative './test_helper'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class TestHtmlParserContext < Minitest::Test
|
|
7
|
-
def test_default_options
|
|
8
|
-
context = LibXML::XML::HTMLParser::Context.new
|
|
9
|
-
assert_equal(0, context.options)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_no_options
|
|
13
|
-
context = LibXML::XML::HTMLParser::Context.new
|
|
14
|
-
context.options = 0
|
|
15
|
-
assert_equal(0, context.options)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_options
|
|
19
|
-
context = LibXML::XML::HTMLParser::Context.new
|
|
20
|
-
context.options = LibXML::XML::HTMLParser::Options::NOERROR
|
|
21
|
-
assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
|
|
22
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestHtmlParserContext < Minitest::Test
|
|
7
|
+
def test_default_options
|
|
8
|
+
context = LibXML::XML::HTMLParser::Context.new
|
|
9
|
+
assert_equal(0, context.options)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_no_options
|
|
13
|
+
context = LibXML::XML::HTMLParser::Context.new
|
|
14
|
+
context.options = 0
|
|
15
|
+
assert_equal(0, context.options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_options
|
|
19
|
+
context = LibXML::XML::HTMLParser::Context.new
|
|
20
|
+
context.options = LibXML::XML::HTMLParser::Options::NOERROR
|
|
21
|
+
assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
|
|
22
|
+
end
|
|
23
23
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
class InputCallbacksGCStressRepro
|
|
6
|
+
def run
|
|
7
|
+
scheme_name = 'input-callback-gc://'
|
|
8
|
+
|
|
9
|
+
callback_class = Class.new do
|
|
10
|
+
def self.document_query(_uri)
|
|
11
|
+
'<root/>'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
LibXML::XML::InputCallbacks.add_scheme(scheme_name, callback_class)
|
|
15
|
+
callback_class = nil
|
|
16
|
+
|
|
17
|
+
document = LibXML::XML::Document.file("#{scheme_name}fixture.xml")
|
|
18
|
+
document.root.name
|
|
19
|
+
ensure
|
|
20
|
+
LibXML::XML::InputCallbacks.remove_scheme(scheme_name)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class TestInputCallbacks < Minitest::Test
|
|
25
|
+
def setup
|
|
26
|
+
GC.stress = true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def teardown
|
|
30
|
+
GC.stress = false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_add_scheme_auto_registers_and_survives_gc_stress
|
|
34
|
+
assert_equal('root', InputCallbacksGCStressRepro.new.run)
|
|
35
|
+
end
|
|
36
|
+
end
|
data/test/test_namespace.rb
CHANGED
|
@@ -31,7 +31,7 @@ class TestNS < Minitest::Test
|
|
|
31
31
|
error = assert_raises(TypeError) do
|
|
32
32
|
LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
|
33
33
|
end
|
|
34
|
-
|
|
34
|
+
assert_match(/wrong argument type nil/, error.to_s)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def test_duplicate_ns
|