nokogiri 1.6.7.2-java → 1.6.8-java
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.
- checksums.yaml +4 -4
- data/.cross_rubies +2 -0
- data/.travis.yml +19 -9
- data/CHANGELOG.rdoc +73 -5
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +10 -9
- data/LICENSE.txt +1 -1
- data/Manifest.txt +7 -2
- data/README.md +23 -27
- data/ROADMAP.md +11 -1
- data/Rakefile +36 -17
- data/bin/nokogiri +2 -2
- data/dependencies.yml +29 -4
- data/ext/java/nokogiri/HtmlElementDescription.java +5 -2
- data/ext/java/nokogiri/NokogiriService.java +19 -0
- data/ext/java/nokogiri/XmlAttr.java +3 -1
- data/ext/java/nokogiri/XmlDocumentFragment.java +0 -14
- data/ext/java/nokogiri/XmlNode.java +106 -63
- data/ext/java/nokogiri/XmlXpathContext.java +12 -12
- data/ext/java/nokogiri/XsltStylesheet.java +11 -4
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +8 -1
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +1 -2
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +7 -7
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -1
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +3 -3
- data/ext/java/nokogiri/internals/ParserContext.java +4 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +18 -13
- data/ext/nokogiri/extconf.rb +163 -79
- data/ext/nokogiri/html_document.c +6 -6
- data/ext/nokogiri/html_element_description.c +1 -1
- data/ext/nokogiri/html_entity_lookup.c +1 -1
- data/ext/nokogiri/html_sax_parser_context.c +4 -4
- data/ext/nokogiri/html_sax_push_parser.c +2 -2
- data/ext/nokogiri/nokogiri.c +0 -7
- data/ext/nokogiri/nokogiri.h +1 -34
- data/ext/nokogiri/xml_attr.c +2 -2
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +20 -22
- data/ext/nokogiri/xml_encoding_handler.c +3 -3
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +56 -17
- data/ext/nokogiri/xml_node.c +73 -67
- data/ext/nokogiri/xml_node_set.c +164 -146
- data/ext/nokogiri/xml_node_set.h +3 -4
- data/ext/nokogiri/xml_processing_instruction.c +2 -2
- data/ext/nokogiri/xml_reader.c +5 -18
- data/ext/nokogiri/xml_sax_parser.c +9 -12
- data/ext/nokogiri/xml_sax_parser_context.c +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -1
- data/ext/nokogiri/xml_schema.c +1 -1
- data/ext/nokogiri/xml_syntax_error.c +0 -4
- data/ext/nokogiri/xml_syntax_error.h +0 -1
- data/ext/nokogiri/xml_text.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +15 -24
- data/ext/nokogiri/xslt_stylesheet.c +6 -6
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +14 -7
- data/lib/nokogiri/css/parser.rb +8 -2
- data/lib/nokogiri/css/parser.y +7 -2
- data/lib/nokogiri/html/document.rb +4 -2
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/document.rb +7 -1
- data/lib/nokogiri/xml/dtd.rb +4 -4
- data/lib/nokogiri/xml/node.rb +6 -10
- data/lib/nokogiri/xml/node_set.rb +3 -3
- data/lib/nokogiri/xml/parse_options.rb +22 -0
- data/lib/serializer.jar +0 -0
- data/lib/xalan.jar +0 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xml-apis.jar +0 -0
- data/tasks/test.rb +5 -0
- data/test/css/test_parser.rb +7 -1
- data/test/files/GH_1042.html +18 -0
- data/test/files/namespace_pressure_test.xml +1684 -0
- data/test/files/tlm.html +2 -1
- data/test/helper.rb +4 -0
- data/test/html/sax/test_parser.rb +2 -2
- data/test/html/test_document.rb +47 -11
- data/test/html/test_document_encoding.rb +55 -58
- data/test/html/test_document_fragment.rb +27 -23
- data/test/html/test_node.rb +16 -0
- data/test/html/test_node_encoding.rb +71 -13
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +14 -0
- data/test/test_css_cache.rb +1 -1
- data/test/test_encoding_handler.rb +2 -0
- data/test/test_xslt_transforms.rb +38 -3
- data/test/xml/sax/test_parser.rb +54 -53
- data/test/xml/test_document.rb +7 -2
- data/test/xml/test_document_encoding.rb +19 -16
- data/test/xml/test_document_fragment.rb +12 -0
- data/test/xml/test_dtd_encoding.rb +0 -2
- data/test/xml/test_namespace.rb +2 -2
- data/test/xml/test_node.rb +15 -4
- data/test/xml/test_node_attributes.rb +6 -0
- data/test/xml/test_node_encoding.rb +49 -87
- data/test/xml/test_node_reparenting.rb +193 -18
- data/test/xml/test_node_set.rb +1 -1
- data/test/xml/test_reader.rb +589 -0
- data/test/xml/test_reader_encoding.rb +100 -102
- data/test/xml/test_unparented_node.rb +14 -1
- data/test/xslt/test_exception_handling.rb +1 -1
- data/test_all +47 -33
- metadata +38 -36
- data/CHANGELOG.ja.rdoc +0 -1057
- data/test/test_reader.rb +0 -558
data/test/test_reader.rb
DELETED
@@ -1,558 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "helper"
|
3
|
-
|
4
|
-
class TestReader < Nokogiri::TestCase
|
5
|
-
def test_from_io_sets_io_as_source
|
6
|
-
io = File.open SNUGGLES_FILE
|
7
|
-
reader = Nokogiri::XML::Reader.from_io(io)
|
8
|
-
assert_equal io, reader.source
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_empty_element?
|
12
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
13
|
-
<xml><city>Paris</city><state/></xml>
|
14
|
-
eoxml
|
15
|
-
|
16
|
-
results = reader.map do |node|
|
17
|
-
if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
|
18
|
-
node.empty_element?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
assert_equal [false, false, nil, nil, true, nil], results
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_self_closing?
|
25
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
26
|
-
<xml><city>Paris</city><state/></xml>
|
27
|
-
eoxml
|
28
|
-
|
29
|
-
results = reader.map do |node|
|
30
|
-
if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
|
31
|
-
node.self_closing?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
assert_equal [false, false, nil, nil, true, nil], results
|
35
|
-
end
|
36
|
-
|
37
|
-
# Issue #831
|
38
|
-
# Make sure that the reader doesn't block reading the entire input
|
39
|
-
def test_reader_blocking
|
40
|
-
rd, wr = IO.pipe()
|
41
|
-
node_out = nil
|
42
|
-
t = Thread.start do
|
43
|
-
reader = Nokogiri::XML::Reader(rd, 'UTF-8')
|
44
|
-
reader.each do |node|
|
45
|
-
node_out = node
|
46
|
-
break
|
47
|
-
end
|
48
|
-
rd.close
|
49
|
-
end
|
50
|
-
sleep(1) # sleep for one second to make sure the reader will actually block for input
|
51
|
-
begin
|
52
|
-
wr.puts "<foo>"
|
53
|
-
wr.puts "<bar/>" * 10000
|
54
|
-
wr.flush
|
55
|
-
rescue Errno::EPIPE
|
56
|
-
end
|
57
|
-
res = t.join(5) # wait 5 seconds for the thread to finish
|
58
|
-
wr.close
|
59
|
-
refute_nil node_out, "Didn't read any nodes, exclude the trivial case"
|
60
|
-
refute_nil res, "Reader blocks trying to read the entire stream"
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_reader_takes_block
|
64
|
-
options = nil
|
65
|
-
Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
|
66
|
-
options = cfg
|
67
|
-
options.nonet.nowarning.dtdattr
|
68
|
-
end
|
69
|
-
assert options.nonet?
|
70
|
-
assert options.nowarning?
|
71
|
-
assert options.dtdattr?
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_nil_raises
|
75
|
-
assert_raises(ArgumentError) {
|
76
|
-
Nokogiri::XML::Reader.from_memory(nil)
|
77
|
-
}
|
78
|
-
assert_raises(ArgumentError) {
|
79
|
-
Nokogiri::XML::Reader.from_io(nil)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_from_io
|
84
|
-
io = File.open SNUGGLES_FILE
|
85
|
-
reader = Nokogiri::XML::Reader.from_io(io)
|
86
|
-
assert_equal false, reader.default?
|
87
|
-
assert_equal [false, false, false, false, false, false, false],
|
88
|
-
reader.map { |x| x.default? }
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_io
|
92
|
-
io = File.open SNUGGLES_FILE
|
93
|
-
reader = Nokogiri::XML::Reader(io)
|
94
|
-
assert_equal false, reader.default?
|
95
|
-
assert_equal [false, false, false, false, false, false, false],
|
96
|
-
reader.map { |x| x.default? }
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_string_io
|
100
|
-
io = StringIO.new(<<-eoxml)
|
101
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
102
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
103
|
-
</x>
|
104
|
-
eoxml
|
105
|
-
reader = Nokogiri::XML::Reader(io)
|
106
|
-
assert_equal false, reader.default?
|
107
|
-
assert_equal [false, false, false, false, false, false, false],
|
108
|
-
reader.map { |x| x.default? }
|
109
|
-
end
|
110
|
-
|
111
|
-
class ReallyBadIO
|
112
|
-
def read(size)
|
113
|
-
'a' * size ** 10
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class ReallyBadIO4Java
|
118
|
-
def read(size=1)
|
119
|
-
'a' * size ** 10
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_io_that_reads_too_much
|
124
|
-
if Nokogiri.jruby?
|
125
|
-
io = ReallyBadIO4Java.new
|
126
|
-
Nokogiri::XML::Reader(io)
|
127
|
-
else
|
128
|
-
io = ReallyBadIO.new
|
129
|
-
Nokogiri::XML::Reader(io)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_in_memory
|
134
|
-
assert Nokogiri::XML::Reader(<<-eoxml)
|
135
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
136
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
137
|
-
</x>
|
138
|
-
eoxml
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_reader_holds_on_to_string
|
142
|
-
xml = <<-eoxml
|
143
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
144
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
145
|
-
</x>
|
146
|
-
eoxml
|
147
|
-
reader = Nokogiri::XML::Reader(xml)
|
148
|
-
assert_equal xml, reader.source
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_default?
|
152
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
153
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
154
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
155
|
-
</x>
|
156
|
-
eoxml
|
157
|
-
assert_equal false, reader.default?
|
158
|
-
assert_equal [false, false, false, false, false, false, false],
|
159
|
-
reader.map { |x| x.default? }
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_value?
|
163
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
164
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
165
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
166
|
-
</x>
|
167
|
-
eoxml
|
168
|
-
assert_equal false, reader.value?
|
169
|
-
assert_equal [false, true, false, true, false, true, false],
|
170
|
-
reader.map { |x| x.value? }
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_read_error_document
|
174
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
175
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
176
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
177
|
-
<foo>
|
178
|
-
</x>
|
179
|
-
eoxml
|
180
|
-
assert_raises(Nokogiri::XML::SyntaxError) do
|
181
|
-
reader.each { |node| }
|
182
|
-
end
|
183
|
-
assert 1, reader.errors.length
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_attributes?
|
187
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
188
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
189
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
190
|
-
</x>
|
191
|
-
eoxml
|
192
|
-
assert_equal false, reader.attributes?
|
193
|
-
assert_equal [true, false, true, false, true, false, true],
|
194
|
-
reader.map { |x| x.attributes? }
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_attributes
|
198
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
199
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
200
|
-
xmlns='http://mothership.connection.com/'
|
201
|
-
>
|
202
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
203
|
-
</x>
|
204
|
-
eoxml
|
205
|
-
assert_equal({}, reader.attributes)
|
206
|
-
assert_equal [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
207
|
-
'xmlns'=>'http://mothership.connection.com/'},
|
208
|
-
{}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
|
209
|
-
{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
210
|
-
'xmlns'=>'http://mothership.connection.com/'}],
|
211
|
-
reader.map { |x| x.attributes }
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_attribute_roundtrip
|
215
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
216
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
217
|
-
xmlns='http://mothership.connection.com/'
|
218
|
-
>
|
219
|
-
<tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
|
220
|
-
</x>
|
221
|
-
eoxml
|
222
|
-
reader.each do |node|
|
223
|
-
node.attributes.each do |key, value|
|
224
|
-
assert_equal value, node.attribute(key)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_attribute_at
|
230
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
231
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
232
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
233
|
-
</x>
|
234
|
-
eoxml
|
235
|
-
assert_nil reader.attribute_at(nil)
|
236
|
-
assert_nil reader.attribute_at(0)
|
237
|
-
assert_equal ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/'],
|
238
|
-
reader.map { |x| x.attribute_at(0) }
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_attribute
|
242
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
243
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
244
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
245
|
-
</x>
|
246
|
-
eoxml
|
247
|
-
assert_nil reader.attribute(nil)
|
248
|
-
assert_nil reader.attribute('awesome')
|
249
|
-
assert_equal [nil, nil, 'true', nil, 'true', nil, nil],
|
250
|
-
reader.map { |x| x.attribute('awesome') }
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_attribute_length
|
254
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
255
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
256
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
257
|
-
</x>
|
258
|
-
eoxml
|
259
|
-
assert_equal 0, reader.attribute_count
|
260
|
-
assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map { |x| x.attribute_count }
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_depth
|
264
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
265
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
266
|
-
<tenderlove:foo>snuggles!</tenderlove:foo>
|
267
|
-
</x>
|
268
|
-
eoxml
|
269
|
-
assert_equal 0, reader.depth
|
270
|
-
assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map { |x| x.depth }
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_encoding
|
274
|
-
string = <<-eoxml
|
275
|
-
<awesome>
|
276
|
-
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
277
|
-
<p xml:lang="ja">日本語が上手です</p>
|
278
|
-
</awesome>
|
279
|
-
eoxml
|
280
|
-
reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
|
281
|
-
assert_equal ['UTF-8'], reader.map { |x| x.encoding }.uniq
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_xml_version
|
285
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
286
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
287
|
-
<tenderlove:foo>snuggles!</tenderlove:foo>
|
288
|
-
</x>
|
289
|
-
eoxml
|
290
|
-
assert_nil reader.xml_version
|
291
|
-
assert_equal ['1.0'], reader.map { |x| x.xml_version }.uniq
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_lang
|
295
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
296
|
-
<awesome>
|
297
|
-
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
298
|
-
<p xml:lang="ja">日本語が上手です</p>
|
299
|
-
</awesome>
|
300
|
-
eoxml
|
301
|
-
assert_nil reader.lang
|
302
|
-
assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
|
303
|
-
reader.map { |x| x.lang }
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_value
|
307
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
308
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
309
|
-
<tenderlove:foo>snuggles!</tenderlove:foo>
|
310
|
-
</x>
|
311
|
-
eoxml
|
312
|
-
assert_nil reader.value
|
313
|
-
assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
|
314
|
-
reader.map { |x| x.value }
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_prefix
|
318
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
319
|
-
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
320
|
-
<edi:foo>hello</edi:foo>
|
321
|
-
</x>
|
322
|
-
eoxml
|
323
|
-
assert_nil reader.prefix
|
324
|
-
assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
|
325
|
-
reader.map { |n| n.prefix }
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_node_type
|
329
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
330
|
-
<x>
|
331
|
-
<y>hello</y>
|
332
|
-
</x>
|
333
|
-
eoxml
|
334
|
-
assert_equal 0, reader.node_type
|
335
|
-
assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map { |n| n.node_type }
|
336
|
-
end
|
337
|
-
|
338
|
-
def test_inner_xml
|
339
|
-
str = "<x><y>hello</y></x>"
|
340
|
-
reader = Nokogiri::XML::Reader.from_memory(str)
|
341
|
-
|
342
|
-
reader.read
|
343
|
-
|
344
|
-
assert_equal "<y>hello</y>", reader.inner_xml
|
345
|
-
end
|
346
|
-
|
347
|
-
def test_outer_xml
|
348
|
-
str = ["<x><y>hello</y></x>", "<y>hello</y>", "hello", "<y/>", "<x/>"]
|
349
|
-
reader = Nokogiri::XML::Reader.from_memory(str.first)
|
350
|
-
|
351
|
-
xml = []
|
352
|
-
reader.map { |node| xml << node.outer_xml }
|
353
|
-
|
354
|
-
assert_equal str, xml
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_outer_xml_with_empty_nodes
|
358
|
-
str = ["<x><y/></x>", "<y/>", "<x/>"]
|
359
|
-
reader = Nokogiri::XML::Reader.from_memory(str.first)
|
360
|
-
|
361
|
-
xml = []
|
362
|
-
reader.map { |node| xml << node.outer_xml }
|
363
|
-
|
364
|
-
assert_equal str, xml
|
365
|
-
end
|
366
|
-
|
367
|
-
def test_state
|
368
|
-
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
|
369
|
-
assert reader.state
|
370
|
-
end
|
371
|
-
|
372
|
-
def test_ns_uri
|
373
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
374
|
-
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
375
|
-
<edi:foo>hello</edi:foo>
|
376
|
-
</x>
|
377
|
-
eoxml
|
378
|
-
assert_nil reader.namespace_uri
|
379
|
-
assert_equal([nil,
|
380
|
-
nil,
|
381
|
-
"http://ecommerce.example.org/schema",
|
382
|
-
nil,
|
383
|
-
"http://ecommerce.example.org/schema",
|
384
|
-
nil,
|
385
|
-
nil],
|
386
|
-
reader.map { |n| n.namespace_uri })
|
387
|
-
end
|
388
|
-
|
389
|
-
def test_local_name
|
390
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
391
|
-
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
392
|
-
<edi:foo>hello</edi:foo>
|
393
|
-
</x>
|
394
|
-
eoxml
|
395
|
-
assert_nil reader.local_name
|
396
|
-
assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
|
397
|
-
reader.map { |n| n.local_name })
|
398
|
-
end
|
399
|
-
|
400
|
-
def test_name
|
401
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
402
|
-
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
403
|
-
<edi:foo>hello</edi:foo>
|
404
|
-
</x>
|
405
|
-
eoxml
|
406
|
-
assert_nil reader.name
|
407
|
-
assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
|
408
|
-
reader.map { |n| n.name })
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_base_uri
|
412
|
-
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
413
|
-
<x xml:base="http://base.example.org/base/">
|
414
|
-
<link href="link"/>
|
415
|
-
<other xml:base="http://other.example.org/"/>
|
416
|
-
<relative xml:base="relative">
|
417
|
-
<link href="stuff" />
|
418
|
-
</relative>
|
419
|
-
</x>
|
420
|
-
eoxml
|
421
|
-
|
422
|
-
assert_nil reader.base_uri
|
423
|
-
assert_equal(["http://base.example.org/base/",
|
424
|
-
"http://base.example.org/base/",
|
425
|
-
"http://base.example.org/base/",
|
426
|
-
"http://base.example.org/base/",
|
427
|
-
"http://other.example.org/",
|
428
|
-
"http://base.example.org/base/",
|
429
|
-
"http://base.example.org/base/relative",
|
430
|
-
"http://base.example.org/base/relative",
|
431
|
-
"http://base.example.org/base/relative",
|
432
|
-
"http://base.example.org/base/relative",
|
433
|
-
"http://base.example.org/base/relative",
|
434
|
-
"http://base.example.org/base/",
|
435
|
-
"http://base.example.org/base/"],
|
436
|
-
reader.map {|n| n.base_uri })
|
437
|
-
end
|
438
|
-
|
439
|
-
def test_xlink_href_without_base_uri
|
440
|
-
reader = Nokogiri::XML::Reader(<<-eoxml)
|
441
|
-
<x xmlns:xlink="http://www.w3.org/1999/xlink">
|
442
|
-
<link xlink:href="#other">Link</link>
|
443
|
-
<other id="other">Linked Element</other>
|
444
|
-
</x>
|
445
|
-
eoxml
|
446
|
-
|
447
|
-
reader.each do |node|
|
448
|
-
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
449
|
-
if node.name == 'link'
|
450
|
-
assert_nil node.base_uri
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
def test_xlink_href_with_base_uri
|
457
|
-
reader = Nokogiri::XML::Reader(<<-eoxml)
|
458
|
-
<x xml:base="http://base.example.org/base/"
|
459
|
-
xmlns:xlink="http://www.w3.org/1999/xlink">
|
460
|
-
<link xlink:href="#other">Link</link>
|
461
|
-
<other id="other">Linked Element</other>
|
462
|
-
</x>
|
463
|
-
eoxml
|
464
|
-
|
465
|
-
reader.each do |node|
|
466
|
-
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
467
|
-
assert_equal node.base_uri, "http://base.example.org/base/"
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
def test_read_from_memory
|
473
|
-
called = false
|
474
|
-
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
|
475
|
-
reader.each do |node|
|
476
|
-
called = true
|
477
|
-
assert node
|
478
|
-
end
|
479
|
-
assert called
|
480
|
-
end
|
481
|
-
|
482
|
-
def test_large_document_smoke_test
|
483
|
-
# simply run on a large document to verify that there no GC issues
|
484
|
-
xml = []
|
485
|
-
xml << "<elements>"
|
486
|
-
10000.times { |j| xml << "<element id=\"#{j}\"/>" }
|
487
|
-
xml << "</elements>"
|
488
|
-
xml = xml.join("\n")
|
489
|
-
|
490
|
-
Nokogiri::XML::Reader.from_memory(xml).each do |e|
|
491
|
-
e.attributes
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
def test_correct_outer_xml_inclusion
|
496
|
-
xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
|
497
|
-
<root-element>
|
498
|
-
<children>
|
499
|
-
<child n="1">
|
500
|
-
<field>child-1</field>
|
501
|
-
</child>
|
502
|
-
<child n="2">
|
503
|
-
<field>child-2</field>
|
504
|
-
</child>
|
505
|
-
<child n="3">
|
506
|
-
<field>child-3</field>
|
507
|
-
</child>
|
508
|
-
</children>
|
509
|
-
</root-element>
|
510
|
-
eoxml
|
511
|
-
|
512
|
-
nodelengths = []
|
513
|
-
has_child2 = []
|
514
|
-
|
515
|
-
xml.each do |node|
|
516
|
-
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
|
517
|
-
nodelengths << node.outer_xml.length
|
518
|
-
has_child2 << !!(node.outer_xml =~ /child-2/)
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
assert_equal(nodelengths[0], nodelengths[1])
|
523
|
-
assert(has_child2[1])
|
524
|
-
assert(!has_child2[0])
|
525
|
-
end
|
526
|
-
|
527
|
-
def test_correct_inner_xml_inclusion
|
528
|
-
xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
|
529
|
-
<root-element>
|
530
|
-
<children>
|
531
|
-
<child n="1">
|
532
|
-
<field>child-1</field>
|
533
|
-
</child>
|
534
|
-
<child n="2">
|
535
|
-
<field>child-2</field>
|
536
|
-
</child>
|
537
|
-
<child n="3">
|
538
|
-
<field>child-3</field>
|
539
|
-
</child>
|
540
|
-
</children>
|
541
|
-
</root-element>
|
542
|
-
eoxml
|
543
|
-
|
544
|
-
nodelengths = []
|
545
|
-
has_child2 = []
|
546
|
-
|
547
|
-
xml.each do |node|
|
548
|
-
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
|
549
|
-
nodelengths << node.inner_xml.length
|
550
|
-
has_child2 << !!(node.inner_xml =~ /child-2/)
|
551
|
-
end
|
552
|
-
end
|
553
|
-
|
554
|
-
assert_equal(nodelengths[0], nodelengths[1])
|
555
|
-
assert(has_child2[1])
|
556
|
-
assert(!has_child2[0])
|
557
|
-
end
|
558
|
-
end
|