nokogiri 1.4.0-x86-mingw32 → 1.4.1-x86-mingw32

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.

Files changed (75) hide show
  1. data/.autotest +5 -6
  2. data/CHANGELOG.ja.rdoc +47 -11
  3. data/CHANGELOG.rdoc +31 -0
  4. data/Manifest.txt +8 -1
  5. data/README.ja.rdoc +4 -3
  6. data/README.rdoc +9 -1
  7. data/Rakefile +4 -0
  8. data/deps.rip +5 -0
  9. data/ext/nokogiri/extconf.rb +4 -0
  10. data/ext/nokogiri/html_element_description.c +1 -1
  11. data/ext/nokogiri/nokogiri.c +7 -0
  12. data/ext/nokogiri/nokogiri.h +4 -1
  13. data/ext/nokogiri/xml_document.c +3 -5
  14. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  15. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  16. data/ext/nokogiri/xml_namespace.c +8 -0
  17. data/ext/nokogiri/xml_namespace.h +1 -0
  18. data/ext/nokogiri/xml_node.c +61 -41
  19. data/ext/nokogiri/xml_node_set.c +22 -14
  20. data/ext/nokogiri/xml_sax_parser.c +0 -3
  21. data/ext/nokogiri/xml_sax_parser_context.c +2 -0
  22. data/ext/nokogiri/xml_sax_push_parser.c +26 -3
  23. data/ext/nokogiri/xml_syntax_error.c +18 -227
  24. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  25. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  26. data/lib/nokogiri/css/generated_parser.rb +173 -160
  27. data/lib/nokogiri/css/generated_tokenizer.rb +4 -1
  28. data/lib/nokogiri/css/parser.y +4 -1
  29. data/lib/nokogiri/css/tokenizer.rex +2 -1
  30. data/lib/nokogiri/css/xpath_visitor.rb +2 -0
  31. data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
  32. data/lib/nokogiri/ffi/html/element_description.rb +5 -9
  33. data/lib/nokogiri/ffi/libxml.rb +21 -5
  34. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
  35. data/lib/nokogiri/ffi/structs/xml_document.rb +3 -3
  36. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +110 -1
  37. data/lib/nokogiri/ffi/xml/dtd.rb +2 -4
  38. data/lib/nokogiri/ffi/xml/node.rb +38 -17
  39. data/lib/nokogiri/ffi/xml/node_set.rb +21 -8
  40. data/lib/nokogiri/ffi/xml/reader.rb +1 -1
  41. data/lib/nokogiri/ffi/xml/sax/parser.rb +1 -8
  42. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +16 -4
  43. data/lib/nokogiri/ffi/xml/syntax_error.rb +9 -2
  44. data/lib/nokogiri/ffi/xslt/stylesheet.rb +12 -9
  45. data/lib/nokogiri/version.rb +1 -1
  46. data/lib/nokogiri/xml/builder.rb +1 -1
  47. data/lib/nokogiri/xml/document.rb +35 -4
  48. data/lib/nokogiri/xml/document_fragment.rb +5 -1
  49. data/lib/nokogiri/xml/fragment_handler.rb +28 -20
  50. data/lib/nokogiri/xml/node.rb +84 -13
  51. data/lib/nokogiri/xml/node_set.rb +19 -2
  52. data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
  53. data/lib/nokogiri/xml/syntax_error.rb +10 -5
  54. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  55. data/lib/xsd/xmlparser/nokogiri.rb +20 -1
  56. data/test/css/test_parser.rb +5 -0
  57. data/test/css/test_tokenizer.rb +7 -0
  58. data/test/helper.rb +0 -5
  59. data/test/html/test_document_fragment.rb +39 -1
  60. data/test/html/test_node.rb +14 -0
  61. data/test/test_encoding_handler.rb +46 -0
  62. data/test/test_memory_leak.rb +10 -0
  63. data/test/test_nokogiri.rb +5 -1
  64. data/test/test_soap4r_sax.rb +52 -0
  65. data/test/test_xslt_transforms.rb +69 -26
  66. data/test/xml/sax/test_parser_context.rb +7 -0
  67. data/test/xml/sax/test_push_parser.rb +33 -0
  68. data/test/xml/test_document.rb +27 -1
  69. data/test/xml/test_document_fragment.rb +6 -0
  70. data/test/xml/test_node.rb +63 -214
  71. data/test/xml/test_node_reparenting.rb +261 -0
  72. data/test/xml/test_node_set.rb +51 -0
  73. data/test/xml/test_syntax_error.rb +0 -15
  74. metadata +13 -4
  75. data/test/test_gc.rb +0 -15
@@ -50,6 +50,13 @@ module Nokogiri
50
50
  ctx.parse_with parser
51
51
  end
52
52
  end
53
+
54
+ def test_parse_with_returns_nil
55
+ xml = "<root />"
56
+ ctx = ParserContext.new xml
57
+ parser = Parser.new Doc.new
58
+ assert_nil ctx.parse_with(parser)
59
+ end
53
60
  end
54
61
  end
55
62
  end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require "helper"
2
4
 
3
5
  module Nokogiri
@@ -100,6 +102,37 @@ module Nokogiri
100
102
  @parser.finish
101
103
  assert_equal [' This is a comment '], @parser.document.comments
102
104
  end
105
+
106
+ def test_default_options
107
+ assert_equal 0, @parser.options
108
+ end
109
+
110
+ def test_recover
111
+ @parser.options |= XML::ParseOptions::RECOVER
112
+ @parser.<<(<<-eoxml)
113
+ <p>
114
+ Foo
115
+ <bar>
116
+ Bar
117
+ </p>
118
+ eoxml
119
+ @parser.finish
120
+ assert(@parser.document.errors.size >= 1)
121
+ assert_equal [["p", []], ["bar", []]], @parser.document.start_elements
122
+ assert_equal "FooBar", @parser.document.data.map { |x|
123
+ x.gsub(/\s/, '')
124
+ }.join
125
+ end
126
+
127
+ def test_broken_encoding
128
+ @parser.options |= XML::ParseOptions::RECOVER
129
+ # This is ISO_8859-1:
130
+ @parser.<< "<?xml version='1.0' encoding='UTF-8'?><r>Gau\337</r>"
131
+ @parser.finish
132
+ assert(@parser.document.errors.size >= 1)
133
+ assert_equal "Gau\337", @parser.document.data.join
134
+ assert_equal [["r"]], @parser.document.end_elements
135
+ end
103
136
  end
104
137
  end
105
138
  end
@@ -10,6 +10,18 @@ module Nokogiri
10
10
  @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
11
11
  end
12
12
 
13
+ def test_collect_namespaces
14
+ doc = Nokogiri::XML(<<-eoxml)
15
+ <xml>
16
+ <foo xmlns='hello'>
17
+ <bar xmlns:foo='world' />
18
+ </foo>
19
+ </xml>
20
+ eoxml
21
+ assert_equal({"xmlns"=>"hello", "xmlns:foo"=>"world"},
22
+ doc.collect_namespaces)
23
+ end
24
+
13
25
  def test_subclass_initialize_modify # testing a segv
14
26
  Class.new(Nokogiri::XML::Document) {
15
27
  def initialize
@@ -96,6 +108,12 @@ module Nokogiri
96
108
  assert_equal '1.0', @xml.version
97
109
  end
98
110
 
111
+ def test_add_namespace
112
+ assert_raise NoMethodError do
113
+ @xml.add_namespace('foo', 'bar')
114
+ end
115
+ end
116
+
99
117
  def test_attributes
100
118
  assert_raise NoMethodError do
101
119
  @xml.attributes
@@ -130,7 +148,7 @@ module Nokogiri
130
148
  assert_equal 0, fragment.children.length
131
149
  end
132
150
 
133
- def test_add_child_with_fragment
151
+ def test_add_child_fragment_with_single_node
134
152
  doc = Nokogiri::XML::Document.new
135
153
  fragment = doc.fragment('<hello />')
136
154
  doc.add_child fragment
@@ -138,6 +156,14 @@ module Nokogiri
138
156
  assert_equal 'hello', doc.root.name
139
157
  end
140
158
 
159
+ def test_add_child_fragment_with_multiple_nodes
160
+ doc = Nokogiri::XML::Document.new
161
+ fragment = doc.fragment('<hello /><goodbye />')
162
+ assert_raises(RuntimeError) do
163
+ doc.add_child fragment
164
+ end
165
+ end
166
+
141
167
  def test_add_child_with_multiple_roots
142
168
  assert_raises(RuntimeError) do
143
169
  @xml << Node.new('foo', @xml)
@@ -27,6 +27,12 @@ module Nokogiri
27
27
  assert_instance_of Nokogiri::XML::DocumentFragment, fragment
28
28
  end
29
29
 
30
+ def test_static_method_with_namespaces
31
+ # follows different path in FragmentHandler#start_element which blew up after 597195ff
32
+ fragment = Nokogiri::XML::DocumentFragment.parse("<o:div>a</o:div>")
33
+ assert_instance_of Nokogiri::XML::DocumentFragment, fragment
34
+ end
35
+
30
36
  def test_many_fragments
31
37
  100.times { Nokogiri::XML::DocumentFragment.new(@xml) }
32
38
  end
@@ -10,6 +10,69 @@ module Nokogiri
10
10
  @xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
11
11
  end
12
12
 
13
+ def test_gt_string_arg
14
+ node = @xml.at('employee')
15
+ nodes = (node > 'name')
16
+ assert_equal 1, nodes.length
17
+ assert_equal node, nodes.first.parent
18
+ end
19
+
20
+ def test_next_element_when_next_sibling_is_element_should_return_next_sibling
21
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
22
+ node = doc.at_css("foo")
23
+ next_element = node.next_element
24
+ assert next_element.element?
25
+ assert_equal doc.at_css("quux"), next_element
26
+ end
27
+
28
+ def test_next_element_when_there_is_no_next_sibling_should_return_nil
29
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
30
+ assert_nil doc.at_css("quux").next_element
31
+ end
32
+
33
+ def test_next_element_when_next_sibling_is_not_an_element_should_return_closest_next_element_sibling
34
+ doc = Nokogiri::XML "<root><foo />bar<quux /></root>"
35
+ node = doc.at_css("foo")
36
+ next_element = node.next_element
37
+ assert next_element.element?
38
+ assert_equal doc.at_css("quux"), next_element
39
+ end
40
+
41
+ def test_next_element_when_next_sibling_is_not_an_element_and_no_following_element_should_return_nil
42
+ doc = Nokogiri::XML "<root><foo />bar</root>"
43
+ node = doc.at_css("foo")
44
+ next_element = node.next_element
45
+ assert_nil next_element
46
+ end
47
+
48
+ def test_previous_element_when_previous_sibling_is_element_should_return_previous_sibling
49
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
50
+ node = doc.at_css("quux")
51
+ previous_element = node.previous_element
52
+ assert previous_element.element?
53
+ assert_equal doc.at_css("foo"), previous_element
54
+ end
55
+
56
+ def test_previous_element_when_there_is_no_previous_sibling_should_return_nil
57
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
58
+ assert_nil doc.at_css("foo").previous_element
59
+ end
60
+
61
+ def test_previous_element_when_previous_sibling_is_not_an_element_should_return_closest_previous_element_sibling
62
+ doc = Nokogiri::XML "<root><foo />bar<quux /></root>"
63
+ node = doc.at_css("quux")
64
+ previous_element = node.previous_element
65
+ assert previous_element.element?
66
+ assert_equal doc.at_css("foo"), previous_element
67
+ end
68
+
69
+ def test_previous_element_when_previous_sibling_is_not_an_element_and_no_following_element_should_return_nil
70
+ doc = Nokogiri::XML "<root>foo<bar /></root>"
71
+ node = doc.at_css("bar")
72
+ previous_element = node.previous_element
73
+ assert_nil previous_element
74
+ end
75
+
13
76
  def test_element?
14
77
  assert @xml.root.element?, 'is an element'
15
78
  end
@@ -93,18 +156,6 @@ module Nokogiri
93
156
  assert_nil @xml.at('employee').description
94
157
  end
95
158
 
96
- def test_add_namespace_add_child
97
- doc = Nokogiri::XML::Document.new
98
- item = Nokogiri::XML::Element.new('item', doc)
99
- doc.root = item
100
-
101
- entry = Nokogiri::XML::Element.new('entry', doc)
102
- entry.add_namespace('tlm', 'http://tenderlovemaking.com')
103
- assert_equal 'http://tenderlovemaking.com', entry.namespaces['xmlns:tlm']
104
- item.add_child(entry)
105
- assert_equal 'http://tenderlovemaking.com', entry.namespaces['xmlns:tlm']
106
- end
107
-
108
159
  def test_spaceship
109
160
  nodes = @xml.xpath('//employee')
110
161
  assert_equal(-1, (nodes.first <=> nodes.last))
@@ -170,13 +221,6 @@ module Nokogiri
170
221
  assert_equal 1, fruits.xpath('//xmlns:Apple').length
171
222
  end
172
223
 
173
- def test_add_child_path_following_sequential_text_nodes
174
- xml = Nokogiri::XML('<root>text</root>')
175
- xml.root.add_child(Nokogiri::XML::Text.new('text', xml))
176
- item = xml.root.add_child(Nokogiri::XML::Element.new('item', xml))
177
- assert_equal '/root/item', item.path
178
- end
179
-
180
224
  def test_new_node_can_have_ancestors
181
225
  xml = Nokogiri::XML('<root>text</root>')
182
226
  item = Nokogiri::XML::Element.new('item', xml)
@@ -317,51 +361,6 @@ module Nokogiri
317
361
  assert visitor.visited
318
362
  end
319
363
 
320
- def test_replace_with_default_namespaces
321
- fruits = Nokogiri::XML(<<-eoxml)
322
- <fruit xmlns="http://fruits.org">
323
- <apple />
324
- </fruit>
325
- eoxml
326
-
327
- apple = fruits.css('apple').first
328
-
329
- orange = Nokogiri::XML::Node.new('orange', fruits)
330
- apple.replace(orange)
331
-
332
- assert_equal orange, fruits.css('orange').first
333
- end
334
-
335
- def test_add_child_should_inherit_namespace
336
- doc = Nokogiri::XML(<<-eoxml)
337
- <root xmlns="http://tenderlovemaking.com/">
338
- <first>
339
- </first>
340
- </root>
341
- eoxml
342
- assert node = doc.at('//xmlns:first')
343
- child = Nokogiri::XML::Node.new('second', doc)
344
- node.add_child(child)
345
- assert doc.at('//xmlns:second')
346
- end
347
-
348
- def test_add_child_should_not_inherit_namespace_if_it_has_one
349
- doc = Nokogiri::XML(<<-eoxml)
350
- <root xmlns="http://tenderlovemaking.com/" xmlns:foo="http://flavorjon.es/">
351
- <first>
352
- </first>
353
- </root>
354
- eoxml
355
- assert node = doc.at('//xmlns:first')
356
- child = Nokogiri::XML::Node.new('second', doc)
357
-
358
- ns = doc.root.namespace_definitions.detect { |x| x.prefix == "foo" }
359
- child.namespace = ns
360
-
361
- node.add_child(child)
362
- assert doc.at('//foo:second', "foo" => "http://flavorjon.es/")
363
- end
364
-
365
364
  def test_write_to
366
365
  io = StringIO.new
367
366
  @xml.write_to io
@@ -478,110 +477,12 @@ module Nokogiri
478
477
  assert_nil address['domestic']
479
478
  end
480
479
 
481
- def test_add_child_in_same_document
482
- child = @xml.css('employee').first
483
-
484
- assert previous_last_child = child.children.last
485
- assert new_child = child.children.first
486
-
487
- last = child.children.last
488
-
489
- child.add_child(new_child)
490
- assert_equal new_child, child.children.last
491
- assert_equal last, child.children.last
492
- end
493
-
494
- def test_add_child_from_other_document
495
- d1 = Nokogiri::XML("<root><item>1</item><item>2</item></root>")
496
- d2 = Nokogiri::XML("<root><item>3</item><item>4</item></root>")
497
-
498
- d2.at('root').search('item').each do |i|
499
- d1.at('root').add_child i
500
- end
501
-
502
- assert_equal 0, d2.search('item').size
503
- assert_equal 4, d1.search('item').size
504
- end
505
-
506
- def test_add_child
507
- xml = Nokogiri::XML(<<-eoxml)
508
- <root>
509
- <a>Hello world</a>
510
- </root>
511
- eoxml
512
- text_node = Nokogiri::XML::Text.new('hello', xml)
513
- assert_equal Nokogiri::XML::Node::TEXT_NODE, text_node.type
514
- xml.root.add_child text_node
515
- assert_match 'hello', xml.to_s
516
- end
517
-
518
- def test_chevron_works_as_add_child
519
- xml = Nokogiri::XML(<<-eoxml)
520
- <root>
521
- <a>Hello world</a>
522
- </root>
523
- eoxml
524
- text_node = Nokogiri::XML::Text.new('hello', xml)
525
- xml.root << text_node
526
- assert_match 'hello', xml.to_s
527
- end
528
-
529
480
  def test_set_content_with_symbol
530
481
  node = @xml.at('//name')
531
482
  node.content = :foo
532
483
  assert_equal 'foo', node.content
533
484
  end
534
485
 
535
- def test_add_previous_sibling
536
- xml = Nokogiri::XML(<<-eoxml)
537
- <root>
538
- <a>Hello world</a>
539
- </root>
540
- eoxml
541
- b_node = Nokogiri::XML::Node.new('a', xml)
542
- assert_equal Nokogiri::XML::Node::ELEMENT_NODE, b_node.type
543
- b_node.content = 'first'
544
- a_node = xml.xpath('//a').first
545
- a_node.add_previous_sibling(b_node)
546
- assert_equal('first', xml.xpath('//a').first.text)
547
- end
548
-
549
- def test_add_previous_sibling_merge
550
- xml = Nokogiri::XML(<<-eoxml)
551
- <root>
552
- <a>Hello world</a>
553
- </root>
554
- eoxml
555
-
556
- assert a_tag = xml.css('a').first
557
-
558
- left_space = a_tag.previous
559
- right_space = a_tag.next
560
- assert left_space.text?
561
- assert right_space.text?
562
-
563
- left_space.add_previous_sibling(right_space)
564
- assert_equal left_space, right_space
565
- end
566
-
567
- def test_add_next_sibling_merge
568
- xml = Nokogiri::XML(<<-eoxml)
569
- <root>
570
- <a>Hello world</a>
571
- </root>
572
- eoxml
573
-
574
- assert a_tag = xml.css('a').first
575
-
576
- left_space = a_tag.previous
577
- right_space = a_tag.next
578
- assert left_space.text?
579
- assert right_space.text?
580
-
581
- right_space.add_next_sibling(left_space)
582
- assert_equal left_space, right_space
583
- end
584
-
585
486
  def test_find_by_css_with_tilde_eql
586
487
  xml = Nokogiri::XML.parse(<<-eoxml)
587
488
  <root>
@@ -715,30 +616,6 @@ module Nokogiri
715
616
  assert_equal " ", children[3]
716
617
  end
717
618
 
718
- def test_replace
719
- set = @xml.search('//employee')
720
- assert 5, set.length
721
- assert 0, @xml.search('//form').length
722
-
723
- first = set[0]
724
- second = set[1]
725
-
726
- node = Nokogiri::XML::Node.new('form', @xml)
727
- first.replace(node)
728
-
729
- assert set = @xml.search('//employee')
730
- assert_equal 4, set.length
731
- assert 1, @xml.search('//form').length
732
-
733
- assert_equal set[0].to_xml, second.to_xml
734
- end
735
-
736
- def test_illegal_replace_of_node_with_doc
737
- new_node = Nokogiri::XML.parse('<foo>bar</foo>')
738
- old_node = @xml.at('//employee')
739
- assert_raises(ArgumentError){ old_node.replace new_node }
740
- end
741
-
742
619
  def test_node_equality
743
620
  doc1 = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
744
621
  doc2 = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
@@ -856,34 +733,6 @@ EOF
856
733
  assert_equal 2, node.line
857
734
  end
858
735
 
859
- def test_unlink_then_reparent
860
- # see http://github.com/tenderlove/nokogiri/issues#issue/22
861
- 10.times do
862
- STDOUT.putc "."
863
- STDOUT.flush
864
- begin
865
- doc = Nokogiri::XML <<-EOHTML
866
- <root>
867
- <a>
868
- <b/>
869
- <c/>
870
- </a>
871
- </root>
872
- EOHTML
873
-
874
- root = doc.at("root")
875
- a = root.at("a")
876
- b = a.at("b")
877
- c = a.at("c")
878
- a.add_next_sibling(b.unlink)
879
- c.unlink
880
- end
881
-
882
- GC.start
883
- end
884
-
885
- end
886
-
887
736
  end
888
737
  end
889
738
  end