nokogiri 1.4.7-x86-mswin32-60 → 1.5.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/CHANGELOG.ja.rdoc +59 -1
- data/CHANGELOG.rdoc +51 -2
- data/Manifest.txt +66 -66
- data/README.ja.rdoc +4 -0
- data/README.rdoc +31 -3
- data/Rakefile +111 -135
- data/bin/nokogiri +1 -2
- data/ext/nokogiri/extconf.rb +9 -3
- data/ext/nokogiri/nokogiri.c +21 -3
- data/ext/nokogiri/nokogiri.h +0 -2
- data/ext/nokogiri/xml_node.c +0 -6
- data/ext/nokogiri/xml_relax_ng.c +0 -7
- data/ext/nokogiri/xml_sax_parser.c +9 -4
- data/ext/nokogiri/xslt_stylesheet.c +5 -1
- data/lib/nokogiri.rb +19 -25
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +0 -1
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +9 -2
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/version.rb +76 -31
- data/lib/nokogiri/xml/attribute_decl.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +7 -0
- data/lib/nokogiri/xml/document.rb +17 -1
- data/lib/nokogiri/xml/document_fragment.rb +14 -0
- data/lib/nokogiri/xml/dtd.rb +1 -1
- data/lib/nokogiri/xml/element_decl.rb +1 -1
- data/lib/nokogiri/xml/entity_decl.rb +1 -1
- data/lib/nokogiri/xml/node.rb +39 -15
- data/lib/nokogiri/xml/node/save_options.rb +14 -5
- data/lib/nokogiri/xml/node_set.rb +7 -0
- data/lib/nokogiri/xml/reader.rb +2 -2
- data/lib/nokogiri/xml/sax/document.rb +2 -2
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +134 -155
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +2 -2
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/helper.rb +2 -1
- data/test/html/sax/test_parser.rb +22 -5
- data/test/html/test_document.rb +21 -2
- data/test/html/test_document_encoding.rb +9 -1
- data/test/html/test_document_fragment.rb +5 -3
- data/test/html/test_element_description.rb +4 -2
- data/test/test_memory_leak.rb +4 -39
- data/test/test_nokogiri.rb +14 -20
- data/test/test_reader.rb +12 -8
- data/test/xml/node/test_save_options.rb +10 -2
- data/test/xml/sax/test_parser.rb +14 -7
- data/test/xml/test_attribute_decl.rb +7 -3
- data/test/xml/test_builder.rb +17 -0
- data/test/xml/test_document.rb +31 -4
- data/test/xml/test_dtd.rb +13 -3
- data/test/xml/test_element_content.rb +1 -1
- data/test/xml/test_element_decl.rb +1 -1
- data/test/xml/test_entity_decl.rb +12 -10
- data/test/xml/test_namespace.rb +7 -5
- data/test/xml/test_node.rb +21 -10
- data/test/xml/test_node_reparenting.rb +16 -3
- data/test/xml/test_node_set.rb +34 -0
- data/test/xslt/test_custom_functions.rb +2 -2
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +110 -88
- data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
- data/lib/nokogiri/ffi/html/document.rb +0 -28
- data/lib/nokogiri/ffi/html/element_description.rb +0 -81
- data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
- data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
- data/lib/nokogiri/ffi/libxml.rb +0 -420
- data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
- data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
- data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
- data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
- data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
- data/lib/nokogiri/ffi/xml/attr.rb +0 -41
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
- data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
- data/lib/nokogiri/ffi/xml/comment.rb +0 -18
- data/lib/nokogiri/ffi/xml/document.rb +0 -174
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
- data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
- data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
- data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
- data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
- data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
- data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
- data/lib/nokogiri/ffi/xml/node.rb +0 -559
- data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
- data/lib/nokogiri/ffi/xml/reader.rb +0 -236
- data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
- data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
- data/lib/nokogiri/ffi/xml/schema.rb +0 -109
- data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
- data/lib/nokogiri/ffi/xml/text.rb +0 -18
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
- data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
- data/lib/nokogiri/version_warning.rb +0 -14
- data/test/ffi/test_document.rb +0 -35
data/test/helper.rb
CHANGED
@@ -7,7 +7,7 @@ require 'pp'
|
|
7
7
|
|
8
8
|
require 'nokogiri'
|
9
9
|
|
10
|
-
warn "#{__FILE__}:#{__LINE__}:
|
10
|
+
warn "#{__FILE__}:#{__LINE__}: version info: #{Nokogiri::VERSION_INFO.inspect}"
|
11
11
|
|
12
12
|
module Nokogiri
|
13
13
|
class TestCase < MiniTest::Spec
|
@@ -23,6 +23,7 @@ module Nokogiri
|
|
23
23
|
ENCODING_XHTML_FILE = File.join(ASSETS_DIR, 'encoding.xhtml')
|
24
24
|
ENCODING_HTML_FILE = File.join(ASSETS_DIR, 'encoding.html')
|
25
25
|
NOENCODING_FILE = File.join(ASSETS_DIR, 'noencoding.html')
|
26
|
+
METACHARSET_FILE = File.join(ASSETS_DIR, 'metacharset.html')
|
26
27
|
PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
|
27
28
|
PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
|
28
29
|
ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
|
@@ -24,7 +24,14 @@ module Nokogiri
|
|
24
24
|
|
25
25
|
def test_parse_file
|
26
26
|
@parser.parse_file(HTML_FILE)
|
27
|
-
|
27
|
+
|
28
|
+
# Take a look at the comment in test_parse_document to know
|
29
|
+
# a possible reason to this difference.
|
30
|
+
if Nokogiri.uses_libxml?
|
31
|
+
assert_equal 1110, @parser.document.end_elements.length
|
32
|
+
else
|
33
|
+
assert_equal 1119, @parser.document.end_elements.length
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def test_parse_file_nil_argument
|
@@ -65,8 +72,20 @@ module Nokogiri
|
|
65
72
|
<p>Paragraph 1</p>
|
66
73
|
<p>Paragraph 2</p>
|
67
74
|
eoxml
|
68
|
-
|
69
|
-
|
75
|
+
|
76
|
+
# JRuby version is different because of the internal implementation
|
77
|
+
# JRuby version uses NekoHTML which inserts empty "head" elements.
|
78
|
+
#
|
79
|
+
# Currently following features are set:
|
80
|
+
# "http://cyberneko.org/html/properties/names/elems" => "lower"
|
81
|
+
# "http://cyberneko.org/html/properties/names/attrs" => "lower"
|
82
|
+
if Nokogiri.uses_libxml?
|
83
|
+
assert_equal([["html", []], ["body", []], ["p", []], ["p", []]],
|
84
|
+
@parser.document.start_elements)
|
85
|
+
else
|
86
|
+
assert_equal([["html", []], ["head", []], ["body", []], ["p", []], ["p", []]],
|
87
|
+
@parser.document.start_elements)
|
88
|
+
end
|
70
89
|
end
|
71
90
|
|
72
91
|
def test_parser_attributes
|
@@ -92,8 +111,6 @@ module Nokogiri
|
|
92
111
|
|
93
112
|
noshade_value = if Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['loaded'] < '2.7.7'
|
94
113
|
['noshade', 'noshade']
|
95
|
-
elsif Nokogiri.jruby?
|
96
|
-
['noshade', '']
|
97
114
|
else
|
98
115
|
['noshade', nil]
|
99
116
|
end
|
data/test/html/test_document.rb
CHANGED
@@ -8,6 +8,12 @@ module Nokogiri
|
|
8
8
|
@html = Nokogiri::HTML.parse(File.read(HTML_FILE))
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_nil_css
|
12
|
+
# Behavior is undefined but shouldn't break
|
13
|
+
assert @html.css(nil)
|
14
|
+
assert @html.xpath(nil)
|
15
|
+
end
|
16
|
+
|
11
17
|
def test_exceptions_remove_newlines
|
12
18
|
errors = @html.errors
|
13
19
|
assert errors.length > 0, 'has errors'
|
@@ -87,7 +93,7 @@ module Nokogiri
|
|
87
93
|
assert_nil doc.root
|
88
94
|
end
|
89
95
|
|
90
|
-
unless %w[2 6] === LIBXML_VERSION.split('.')[0..1]
|
96
|
+
unless Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
|
91
97
|
# FIXME: this is a hack around broken libxml versions
|
92
98
|
def test_to_xhtml_with_indent
|
93
99
|
doc = Nokogiri::HTML('<html><body><a>foo</a></body></html>')
|
@@ -178,7 +184,11 @@ eohtml
|
|
178
184
|
</html>
|
179
185
|
eohtml
|
180
186
|
doc.title = 'new'
|
181
|
-
|
187
|
+
if Nokogiri.uses_libxml?
|
188
|
+
assert_nil doc.title
|
189
|
+
else
|
190
|
+
assert_equal 'new', doc.title
|
191
|
+
end
|
182
192
|
end
|
183
193
|
|
184
194
|
def test_meta_encoding_without_head
|
@@ -222,6 +232,15 @@ eohtml
|
|
222
232
|
}
|
223
233
|
end
|
224
234
|
|
235
|
+
def test_parse_temp_file
|
236
|
+
temp_html_file = Tempfile.new("TEMP_HTML_FILE")
|
237
|
+
File.open(HTML_FILE, 'rb') { |f| temp_html_file.write f.read }
|
238
|
+
temp_html_file.close
|
239
|
+
temp_html_file.open
|
240
|
+
assert_equal Nokogiri::HTML.parse(File.read(HTML_FILE)).xpath('//div/a').length,
|
241
|
+
Nokogiri::HTML.parse(temp_html_file).xpath('//div/a').length
|
242
|
+
end
|
243
|
+
|
225
244
|
def test_to_xhtml
|
226
245
|
assert_match 'XHTML', @html.to_xhtml
|
227
246
|
assert_match 'XHTML', @html.to_xhtml(:encoding => 'UTF-8')
|
@@ -96,6 +96,12 @@ module Nokogiri
|
|
96
96
|
assert_equal from_string.to_s.size, from_stream.to_s.size
|
97
97
|
end
|
98
98
|
|
99
|
+
def test_document_html_charset
|
100
|
+
html = Nokogiri::HTML(binopen(METACHARSET_FILE))
|
101
|
+
assert_equal 'iso-2022-jp', html.encoding
|
102
|
+
assert_equal 'たこ焼き仮面', html.title
|
103
|
+
end
|
104
|
+
|
99
105
|
def test_document_xhtml_enc
|
100
106
|
[ENCODING_XHTML_FILE, ENCODING_HTML_FILE].each { |file|
|
101
107
|
doc_from_string_enc = Nokogiri::HTML(binread(file), nil, 'Shift_JIS')
|
@@ -115,7 +121,9 @@ module Nokogiri
|
|
115
121
|
assert_equal(title, doc_from_string_enc.at('//title/text()').text)
|
116
122
|
assert_equal(title, doc_from_string.at('//title/text()').text)
|
117
123
|
assert_equal(title, doc_from_file_enc.at('//title/text()').text)
|
118
|
-
|
124
|
+
unless Nokogiri.jruby? && file == ENCODING_HTML_FILE
|
125
|
+
assert_equal(title, doc_from_file.at('//title/text()').text)
|
126
|
+
end
|
119
127
|
|
120
128
|
evil = (0..72).map { |i| '超' * i + '悪い事を構想中。' }
|
121
129
|
|
@@ -133,7 +133,8 @@ module Nokogiri
|
|
133
133
|
def test_html_fragment_has_outer_text
|
134
134
|
doc = "a<div>b</div>c"
|
135
135
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
136
|
-
if Nokogiri
|
136
|
+
if Nokogiri.uses_libxml? &&
|
137
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.6.16"
|
137
138
|
assert_equal "a<div>b</div><p>c</p>", fragment.to_s
|
138
139
|
else
|
139
140
|
assert_equal "a<div>b</div>c", fragment.to_s
|
@@ -189,7 +190,8 @@ module Nokogiri
|
|
189
190
|
def test_to_xhtml
|
190
191
|
doc = "<span>foo<br></span><span>bar</span>"
|
191
192
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
192
|
-
if Nokogiri
|
193
|
+
if !Nokogiri.uses_libxml? ||
|
194
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
|
193
195
|
assert_equal "<span>foo<br /></span><span>bar</span>", fragment.to_xhtml
|
194
196
|
else
|
195
197
|
assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_xhtml
|
@@ -246,7 +248,7 @@ module Nokogiri
|
|
246
248
|
context_node = doc.at_css "div"
|
247
249
|
frag = Nokogiri::HTML::DocumentFragment.new doc, "<hello>oh, hello there.</hello>", context_node
|
248
250
|
assert frag.errors.any?{|err| err.to_s =~ /Tag hello invalid/}, "errors should be on the context node's document"
|
249
|
-
assert
|
251
|
+
assert frag.errors.none?{|err| err.to_s =~ /jimmy/}, "errors should not include pre-existing document errors"
|
250
252
|
end
|
251
253
|
end
|
252
254
|
end
|
@@ -56,10 +56,12 @@ module Nokogiri
|
|
56
56
|
|
57
57
|
def test_subelements
|
58
58
|
sub_elements = ElementDescription['body'].sub_elements
|
59
|
-
if Nokogiri::LIBXML_VERSION >= '2.7.7'
|
59
|
+
if Nokogiri.uses_libxml? && Nokogiri::LIBXML_VERSION >= '2.7.7'
|
60
60
|
assert_equal 65, sub_elements.length
|
61
|
-
|
61
|
+
elsif Nokogiri.uses_libxml?
|
62
62
|
assert_equal 61, sub_elements.length
|
63
|
+
else
|
64
|
+
assert sub_elements.length > 0
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
data/test/test_memory_leak.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
class TestMemoryLeak < Nokogiri::TestCase
|
4
|
-
|
5
4
|
if ENV['NOKOGIRI_GC'] # turning these off by default for now
|
6
|
-
|
7
5
|
def test_dont_hurt_em_why
|
8
6
|
content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
|
9
7
|
ndoc = Nokogiri::XML(content)
|
@@ -13,20 +11,20 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
13
11
|
GC.start
|
14
12
|
end
|
15
13
|
end
|
16
|
-
|
14
|
+
|
17
15
|
class BadIO
|
18
16
|
def read(*args)
|
19
17
|
raise 'hell'
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
def write(*args)
|
23
21
|
raise 'chickens'
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
27
25
|
def test_for_mem_leak_on_io_callbacks
|
28
26
|
io = File.open SNUGGLES_FILE
|
29
|
-
|
27
|
+
Nokogiri::XML.parse(io)
|
30
28
|
|
31
29
|
(10**10).times do
|
32
30
|
Nokogiri::XML.parse(BadIO.new) rescue nil
|
@@ -62,39 +60,6 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
62
60
|
puts "\ndike is not installed, skipping memory leak test"
|
63
61
|
end
|
64
62
|
end
|
65
|
-
|
66
|
-
if Nokogiri.ffi?
|
67
|
-
[ ['Node', 'p', nil],
|
68
|
-
['CDATA', nil, 'content'],
|
69
|
-
['Comment', nil, 'content'],
|
70
|
-
['DocumentFragment', nil],
|
71
|
-
['EntityReference', nil, 'p'],
|
72
|
-
['ProcessingInstruction', nil, 'p', 'content'] ].each do |klass, *args|
|
73
|
-
|
74
|
-
define_method "test_for_leaked_#{klass}_nodes" do
|
75
|
-
Nokogiri::LibXML.expects(:xmlAddChild).at_least(1) # more than once shows we're GCing properly
|
76
|
-
10.times {
|
77
|
-
xml = Nokogiri::XML("<root></root>")
|
78
|
-
2.times { Nokogiri::XML.const_get(klass).new(*(args.collect{|arg| arg || xml})) }
|
79
|
-
GC.start
|
80
|
-
}
|
81
|
-
GC.start
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_for_leaked_attr_nodes
|
87
|
-
Nokogiri::LibXML.expects(:xmlFreePropList).at_least(1) # more than once shows we're GCing properly
|
88
|
-
10.times {
|
89
|
-
xml = Nokogiri::XML("<root></root>")
|
90
|
-
2.times { Nokogiri::XML::Attr.new(xml, "p") }
|
91
|
-
GC.start
|
92
|
-
}
|
93
|
-
GC.start
|
94
|
-
end
|
95
|
-
|
96
|
-
end # if ffi
|
97
|
-
|
98
63
|
end # if NOKOGIRI_GC
|
99
64
|
|
100
65
|
private
|
data/test/test_nokogiri.rb
CHANGED
@@ -4,34 +4,28 @@ class TestNokogiri < Nokogiri::TestCase
|
|
4
4
|
def test_versions
|
5
5
|
version_match = /\d+\.\d+\.\d+/
|
6
6
|
assert_match version_match, Nokogiri::VERSION
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
assert_equal 'ruby', Nokogiri::VERSION_INFO['libxml']['platform']
|
15
|
-
end
|
16
|
-
assert Nokogiri.ffi?
|
17
|
-
else
|
7
|
+
|
8
|
+
assert_equal Nokogiri::VERSION_INFO['ruby']['version'], ::RUBY_VERSION
|
9
|
+
assert_equal Nokogiri::VERSION_INFO['ruby']['platform'], ::RUBY_PLATFORM
|
10
|
+
|
11
|
+
if Nokogiri.uses_libxml?
|
12
|
+
assert_match version_match, Nokogiri::LIBXML_VERSION
|
18
13
|
assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
|
19
14
|
|
20
15
|
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
|
21
16
|
assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
|
22
|
-
assert ! Nokogiri.ffi?
|
23
|
-
end
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
|
19
|
+
Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
|
20
|
+
major = $1.to_i
|
21
|
+
minor = $2.to_i
|
22
|
+
bug = $3.to_i
|
23
|
+
assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
|
24
|
+
end
|
31
25
|
end
|
32
26
|
|
33
27
|
def test_libxml_iconv
|
34
|
-
assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED)
|
28
|
+
assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
|
35
29
|
end
|
36
30
|
|
37
31
|
def test_parse_with_io
|
data/test/test_reader.rb
CHANGED
@@ -88,8 +88,17 @@ class TestReader < Nokogiri::TestCase
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
def
|
91
|
+
class ReallyBadIO4Java
|
92
|
+
def read(size=1)
|
93
|
+
'a' * size ** 10
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_io_that_reads_too_much
|
98
|
+
if Nokogiri.jruby?
|
99
|
+
io = ReallyBadIO4Java.new
|
100
|
+
Nokogiri::XML::Reader(io)
|
101
|
+
else
|
93
102
|
io = ReallyBadIO.new
|
94
103
|
Nokogiri::XML::Reader(io)
|
95
104
|
end
|
@@ -110,12 +119,7 @@ class TestReader < Nokogiri::TestCase
|
|
110
119
|
</x>
|
111
120
|
eoxml
|
112
121
|
reader = Nokogiri::XML::Reader(xml)
|
113
|
-
|
114
|
-
assert_not_nil reader.source
|
115
|
-
assert reader.source.is_a?(FFI::MemoryPointer)
|
116
|
-
else
|
117
|
-
assert_equal xml, reader.source
|
118
|
-
end
|
122
|
+
assert_equal xml, reader.source
|
119
123
|
end
|
120
124
|
|
121
125
|
def test_default?
|
@@ -5,14 +5,22 @@ module Nokogiri
|
|
5
5
|
class Node
|
6
6
|
class TestSaveOptions < Nokogiri::TestCase
|
7
7
|
SaveOptions.constants.each do |constant|
|
8
|
-
class_eval
|
8
|
+
class_eval <<-EOEVAL
|
9
9
|
def test_predicate_#{constant.downcase}
|
10
10
|
options = SaveOptions.new(SaveOptions::#{constant})
|
11
11
|
assert options.#{constant.downcase}?
|
12
12
|
|
13
13
|
assert SaveOptions.new.#{constant.downcase}.#{constant.downcase}?
|
14
14
|
end
|
15
|
-
|
15
|
+
EOEVAL
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_default_xml_save_options
|
19
|
+
if Nokogiri.jruby?
|
20
|
+
assert_equal 0, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
|
21
|
+
else
|
22
|
+
assert_equal SaveOptions::FORMAT, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/test/xml/sax/test_parser.rb
CHANGED
@@ -95,6 +95,7 @@ module Nokogiri
|
|
95
95
|
<foo:bar>hello world</foo:bar>
|
96
96
|
</root>
|
97
97
|
eoxml
|
98
|
+
|
98
99
|
assert @parser.document.start_elements_namespace.length > 0
|
99
100
|
el = @parser.document.start_elements_namespace[1]
|
100
101
|
assert_equal 'a', el.first
|
@@ -144,8 +145,12 @@ module Nokogiri
|
|
144
145
|
end
|
145
146
|
|
146
147
|
def test_start_is_called_without_namespace
|
147
|
-
@parser.parse(
|
148
|
-
|
148
|
+
@parser.parse(<<-eoxml)
|
149
|
+
<root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
|
150
|
+
<foo:f><bar></foo:f>
|
151
|
+
</root>
|
152
|
+
eoxml
|
153
|
+
assert_equal ['root', 'foo:f', 'bar'],
|
149
154
|
@parser.document.start_elements.map { |x| x.first }
|
150
155
|
end
|
151
156
|
|
@@ -303,11 +308,13 @@ module Nokogiri
|
|
303
308
|
@parser.document.start_elements
|
304
309
|
end
|
305
310
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
+
if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
|
312
|
+
def test_parse_document
|
313
|
+
@parser.parse_memory(<<-eoxml)
|
314
|
+
<p>Paragraph 1</p>
|
315
|
+
<p>Paragraph 2</p>
|
316
|
+
eoxml
|
317
|
+
end
|
311
318
|
end
|
312
319
|
|
313
320
|
def test_parser_attributes
|
@@ -9,7 +9,7 @@ module Nokogiri
|
|
9
9
|
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
10
10
|
<!DOCTYPE staff SYSTEM "staff.dtd" [
|
11
11
|
<!ATTLIST br width CDATA "0">
|
12
|
-
<!ATTLIST a width CDATA >
|
12
|
+
<!ATTLIST a width CDATA "0">
|
13
13
|
<!ATTLIST payment type (check|cash) "cash">
|
14
14
|
]>
|
15
15
|
<root />
|
@@ -64,12 +64,16 @@ module Nokogiri
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_attribute_type
|
67
|
-
|
67
|
+
if Nokogiri.uses_libxml?
|
68
|
+
assert_equal 1, @attr_decl.attribute_type
|
69
|
+
else
|
70
|
+
assert_equal 'CDATA', @attr_decl.attribute_type
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
def test_default
|
71
75
|
assert_equal '0', @attr_decl.default
|
72
|
-
|
76
|
+
assert_equal '0', @attrs[1].default
|
73
77
|
end
|
74
78
|
|
75
79
|
def test_enumeration
|
data/test/xml/test_builder.rb
CHANGED
@@ -3,6 +3,23 @@ require "helper"
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
5
|
class TestBuilder < Nokogiri::TestCase
|
6
|
+
def test_attribute_sensitivity
|
7
|
+
xml = Nokogiri::XML::Builder.new { |x|
|
8
|
+
x.tag "hello", "abcDef" => "world"
|
9
|
+
}.to_xml
|
10
|
+
doc = Nokogiri.XML xml
|
11
|
+
assert_equal 'world', doc.root['abcDef']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_builder_escape
|
15
|
+
xml = Nokogiri::XML::Builder.new { |x|
|
16
|
+
x.condition "value < 1", :attr => "value < 1"
|
17
|
+
}.to_xml
|
18
|
+
doc = Nokogiri.XML xml
|
19
|
+
assert_equal 'value < 1', doc.root['attr']
|
20
|
+
assert_equal 'value < 1', doc.root.content
|
21
|
+
end
|
22
|
+
|
6
23
|
def test_builder_namespace
|
7
24
|
doc = Nokogiri::XML::Builder.new { |xml|
|
8
25
|
xml.a("xmlns:a" => "x") do
|