nokogiri 1.9.0.rc1-java → 1.9.1-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.

Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nokogiri/css/parser.rb +61 -61
  3. data/lib/nokogiri/nokogiri.jar +0 -0
  4. data/lib/nokogiri/version.rb +1 -1
  5. data/lib/nokogiri/xml/document_fragment.rb +1 -1
  6. metadata +4 -146
  7. data/.autotest +0 -22
  8. data/.cross_rubies +0 -8
  9. data/.editorconfig +0 -17
  10. data/.gemtest +0 -0
  11. data/.travis.yml +0 -63
  12. data/CHANGELOG.md +0 -1402
  13. data/CONTRIBUTING.md +0 -42
  14. data/C_CODING_STYLE.rdoc +0 -33
  15. data/Gemfile +0 -23
  16. data/Gemfile-libxml-ruby +0 -3
  17. data/Manifest.txt +0 -371
  18. data/ROADMAP.md +0 -111
  19. data/Rakefile +0 -358
  20. data/SECURITY.md +0 -19
  21. data/STANDARD_RESPONSES.md +0 -47
  22. data/Y_U_NO_GEMSPEC.md +0 -155
  23. data/appveyor.yml +0 -29
  24. data/build_all +0 -48
  25. data/patches/sort-patches-by-date +0 -25
  26. data/suppressions/README.txt +0 -1
  27. data/suppressions/nokogiri_ruby-2.supp +0 -10
  28. data/tasks/test.rb +0 -100
  29. data/test/css/test_nthiness.rb +0 -226
  30. data/test/css/test_parser.rb +0 -386
  31. data/test/css/test_tokenizer.rb +0 -215
  32. data/test/css/test_xpath_visitor.rb +0 -96
  33. data/test/decorators/test_slop.rb +0 -23
  34. data/test/files/2ch.html +0 -108
  35. data/test/files/GH_1042.html +0 -18
  36. data/test/files/address_book.rlx +0 -12
  37. data/test/files/address_book.xml +0 -10
  38. data/test/files/atom.xml +0 -344
  39. data/test/files/bar/bar.xsd +0 -4
  40. data/test/files/bogus.xml +0 -0
  41. data/test/files/dont_hurt_em_why.xml +0 -422
  42. data/test/files/encoding.html +0 -82
  43. data/test/files/encoding.xhtml +0 -84
  44. data/test/files/exslt.xml +0 -8
  45. data/test/files/exslt.xslt +0 -35
  46. data/test/files/foo/foo.xsd +0 -4
  47. data/test/files/metacharset.html +0 -10
  48. data/test/files/namespace_pressure_test.xml +0 -1684
  49. data/test/files/noencoding.html +0 -47
  50. data/test/files/po.xml +0 -32
  51. data/test/files/po.xsd +0 -66
  52. data/test/files/saml/saml20assertion_schema.xsd +0 -283
  53. data/test/files/saml/saml20protocol_schema.xsd +0 -302
  54. data/test/files/saml/xenc_schema.xsd +0 -146
  55. data/test/files/saml/xmldsig_schema.xsd +0 -318
  56. data/test/files/shift_jis.html +0 -10
  57. data/test/files/shift_jis.xml +0 -5
  58. data/test/files/shift_jis_no_charset.html +0 -9
  59. data/test/files/slow-xpath.xml +0 -25509
  60. data/test/files/snuggles.xml +0 -3
  61. data/test/files/staff.dtd +0 -10
  62. data/test/files/staff.xml +0 -59
  63. data/test/files/staff.xslt +0 -32
  64. data/test/files/test_document_url/bar.xml +0 -2
  65. data/test/files/test_document_url/document.dtd +0 -4
  66. data/test/files/test_document_url/document.xml +0 -6
  67. data/test/files/tlm.html +0 -851
  68. data/test/files/to_be_xincluded.xml +0 -2
  69. data/test/files/valid_bar.xml +0 -2
  70. data/test/files/xinclude.xml +0 -4
  71. data/test/helper.rb +0 -271
  72. data/test/html/sax/test_parser.rb +0 -168
  73. data/test/html/sax/test_parser_context.rb +0 -46
  74. data/test/html/sax/test_parser_text.rb +0 -163
  75. data/test/html/sax/test_push_parser.rb +0 -87
  76. data/test/html/test_attributes.rb +0 -85
  77. data/test/html/test_builder.rb +0 -164
  78. data/test/html/test_document.rb +0 -722
  79. data/test/html/test_document_encoding.rb +0 -143
  80. data/test/html/test_document_fragment.rb +0 -310
  81. data/test/html/test_element_description.rb +0 -105
  82. data/test/html/test_named_characters.rb +0 -14
  83. data/test/html/test_node.rb +0 -212
  84. data/test/html/test_node_encoding.rb +0 -91
  85. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
  86. data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
  87. data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
  88. data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
  89. data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
  90. data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
  91. data/test/namespaces/test_namespaces_preservation.rb +0 -31
  92. data/test/test_convert_xpath.rb +0 -135
  93. data/test/test_css_cache.rb +0 -47
  94. data/test/test_encoding_handler.rb +0 -48
  95. data/test/test_memory_leak.rb +0 -226
  96. data/test/test_nokogiri.rb +0 -138
  97. data/test/test_soap4r_sax.rb +0 -52
  98. data/test/test_xslt_transforms.rb +0 -314
  99. data/test/xml/node/test_save_options.rb +0 -28
  100. data/test/xml/node/test_subclass.rb +0 -44
  101. data/test/xml/sax/test_parser.rb +0 -402
  102. data/test/xml/sax/test_parser_context.rb +0 -115
  103. data/test/xml/sax/test_parser_text.rb +0 -202
  104. data/test/xml/sax/test_push_parser.rb +0 -265
  105. data/test/xml/test_attr.rb +0 -96
  106. data/test/xml/test_attribute_decl.rb +0 -86
  107. data/test/xml/test_builder.rb +0 -353
  108. data/test/xml/test_c14n.rb +0 -180
  109. data/test/xml/test_cdata.rb +0 -54
  110. data/test/xml/test_comment.rb +0 -40
  111. data/test/xml/test_document.rb +0 -982
  112. data/test/xml/test_document_encoding.rb +0 -31
  113. data/test/xml/test_document_fragment.rb +0 -312
  114. data/test/xml/test_dtd.rb +0 -187
  115. data/test/xml/test_dtd_encoding.rb +0 -31
  116. data/test/xml/test_element_content.rb +0 -56
  117. data/test/xml/test_element_decl.rb +0 -73
  118. data/test/xml/test_entity_decl.rb +0 -122
  119. data/test/xml/test_entity_reference.rb +0 -262
  120. data/test/xml/test_namespace.rb +0 -96
  121. data/test/xml/test_node.rb +0 -1379
  122. data/test/xml/test_node_attributes.rb +0 -115
  123. data/test/xml/test_node_encoding.rb +0 -75
  124. data/test/xml/test_node_inheritance.rb +0 -32
  125. data/test/xml/test_node_reparenting.rb +0 -661
  126. data/test/xml/test_node_set.rb +0 -828
  127. data/test/xml/test_parse_options.rb +0 -64
  128. data/test/xml/test_processing_instruction.rb +0 -30
  129. data/test/xml/test_reader.rb +0 -620
  130. data/test/xml/test_reader_encoding.rb +0 -134
  131. data/test/xml/test_relax_ng.rb +0 -60
  132. data/test/xml/test_schema.rb +0 -142
  133. data/test/xml/test_syntax_error.rb +0 -36
  134. data/test/xml/test_text.rb +0 -69
  135. data/test/xml/test_unparented_node.rb +0 -483
  136. data/test/xml/test_xinclude.rb +0 -83
  137. data/test/xml/test_xpath.rb +0 -470
  138. data/test/xslt/test_custom_functions.rb +0 -133
  139. data/test/xslt/test_exception_handling.rb +0 -37
@@ -1,115 +0,0 @@
1
- require "helper"
2
-
3
- module Nokogiri
4
- module XML
5
- class TestNodeAttributes < Nokogiri::TestCase
6
- def test_attribute_with_ns
7
- doc = Nokogiri::XML <<-eoxml
8
- <root xmlns:tlm='http://tenderlovemaking.com/'>
9
- <node tlm:foo='bar' foo='baz' />
10
- </root>
11
- eoxml
12
-
13
- node = doc.at('node')
14
-
15
- assert_equal 'bar',
16
- node.attribute_with_ns('foo', 'http://tenderlovemaking.com/').value
17
- end
18
-
19
- def test_prefixed_attributes
20
- doc = Nokogiri::XML "<root xml:lang='en-GB' />"
21
-
22
- node = doc.root
23
-
24
- assert_equal 'en-GB', node['xml:lang']
25
- assert_equal 'en-GB', node.attributes['lang'].value
26
- assert_nil node['lang']
27
- end
28
-
29
- def test_unknown_namespace_prefix_should_not_be_removed
30
- doc = Nokogiri::XML ''
31
- elem = doc.create_element 'foo', 'bar:attr' => 'something'
32
- assert_equal elem.attribute_nodes.first.name, 'bar:attr'
33
- end
34
-
35
- def test_set_prefixed_attributes
36
- doc = Nokogiri::XML %Q{<root xmlns:foo="x"/>}
37
-
38
- node = doc.root
39
-
40
- node['xml:lang'] = 'en-GB'
41
- node['foo:bar'] = 'bazz'
42
-
43
- assert_equal 'en-GB', node['xml:lang']
44
- assert_equal 'en-GB', node.attributes['lang'].value
45
- assert_nil node['lang']
46
- assert_equal 'http://www.w3.org/XML/1998/namespace', node.attributes['lang'].namespace.href
47
-
48
- assert_equal 'bazz', node['foo:bar']
49
- assert_equal 'bazz', node.attributes['bar'].value
50
- assert_nil node['bar']
51
- assert_equal 'x', node.attributes['bar'].namespace.href
52
- end
53
-
54
- def test_append_child_namespace_definitions_prefixed_attributes
55
- doc = Nokogiri::XML "<root/>"
56
- node = doc.root
57
-
58
- node['xml:lang'] = 'en-GB'
59
-
60
- assert_equal [], node.namespace_definitions.map(&:prefix)
61
-
62
- child_node = Nokogiri::XML::Node.new 'foo', doc
63
- node << child_node
64
-
65
- assert_equal [], node.namespace_definitions.map(&:prefix)
66
- end
67
-
68
- def test_append_child_element_with_prefixed_attributes
69
- doc = Nokogiri::XML "<root/>"
70
- node = doc.root
71
-
72
- assert_equal [], node.namespace_definitions.map(&:prefix)
73
-
74
-
75
- # assert_nothing_raised do
76
- child_node = Nokogiri::XML::Node.new 'foo', doc
77
- child_node['xml:lang'] = 'en-GB'
78
-
79
- node << child_node
80
- # end
81
-
82
- assert_equal [], child_node.namespace_definitions.map(&:prefix)
83
- end
84
-
85
- def test_namespace_key?
86
- doc = Nokogiri::XML <<-eoxml
87
- <root xmlns:tlm='http://tenderlovemaking.com/'>
88
- <node tlm:foo='bar' foo='baz' />
89
- </root>
90
- eoxml
91
-
92
- node = doc.at('node')
93
-
94
- assert node.namespaced_key?('foo', 'http://tenderlovemaking.com/')
95
- assert node.namespaced_key?('foo', nil)
96
- assert !node.namespaced_key?('foo', 'foo')
97
- end
98
-
99
- def test_set_attribute_frees_nodes # testing a segv
100
- skip("JRuby doesn't do GC.") if Nokogiri.jruby?
101
- document = Nokogiri::XML.parse("<foo></foo>")
102
-
103
- node = document.root
104
- node['visible'] = 'foo'
105
- attribute = node.attribute('visible')
106
- text = Nokogiri::XML::Text.new 'bar', document
107
- attribute.add_child(text)
108
-
109
- stress_memory_while do
110
- node['visible'] = 'attr'
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,75 +0,0 @@
1
- # encoding: UTF-8
2
- require "helper"
3
-
4
- module Nokogiri
5
- module XML
6
- class TestNodeEncoding < Nokogiri::TestCase
7
- def test_serialize_encoding_xml
8
- @xml = Nokogiri::XML(File.open(SHIFT_JIS_XML))
9
- assert_equal @xml.encoding.downcase,
10
- @xml.serialize.encoding.name.downcase
11
-
12
- @doc = Nokogiri::XML(@xml.serialize)
13
- assert_equal @xml.serialize, @doc.serialize
14
- end
15
-
16
- def test_default_encoding
17
- doc = Nokogiri::XML(VEHICLE_XML)
18
- assert_nil doc.encoding
19
- assert_equal 'UTF-8', doc.serialize.encoding.name
20
- end
21
-
22
- def test_encoding_GH_1113
23
- utf8 = '<frag>shahid ὡ 𐄣 𢂁</frag>'
24
- hex = '<frag>shahid &#x1f61; &#x10123; &#x22081;</frag>'
25
- decimal = '<frag>shahid &#8033; &#65827; &#139393;</frag>'
26
- expected = Nokogiri.jruby? ? hex : decimal
27
-
28
- frag = Nokogiri::XML(utf8, nil, 'UTF-8', Nokogiri::XML::ParseOptions::STRICT)
29
- assert_equal utf8, frag.to_xml.sub(/^<.xml[^>]*>\n/m, '').strip
30
-
31
- frag = Nokogiri::XML(expected, nil, 'UTF-8', Nokogiri::XML::ParseOptions::STRICT)
32
- assert_equal utf8, frag.to_xml.sub(/^<.xml[^>]*>\n/m, '').strip
33
-
34
- frag = Nokogiri::XML(expected, nil, 'US-ASCII', Nokogiri::XML::ParseOptions::STRICT)
35
- assert_equal expected, frag.to_xml.sub(/^<.xml[^>]*>\n/m, '').strip
36
- end
37
-
38
- VEHICLE_XML = <<-eoxml
39
- <root>
40
- <car xmlns:part="http://general-motors.com/">
41
- <part:tire>Michelin Model XGV</part:tire>
42
- </car>
43
- <bicycle xmlns:part="http://schwinn.com/">
44
- <part:tire>I'm a bicycle tire!</part:tire>
45
- </bicycle>
46
- </root>
47
- eoxml
48
-
49
- def test_namespace
50
- doc = Nokogiri::XML(VEHICLE_XML.encode('Shift_JIS'), nil, 'Shift_JIS')
51
- assert_equal 'Shift_JIS', doc.encoding
52
- n = doc.xpath('//part:tire', { 'part' => 'http://schwinn.com/' }).first
53
- assert n
54
- assert_equal 'UTF-8', n.namespace.href.encoding.name
55
- assert_equal 'UTF-8', n.namespace.prefix.encoding.name
56
- end
57
-
58
- def test_namespace_as_hash
59
- doc = Nokogiri::XML(VEHICLE_XML.encode('Shift_JIS'), nil, 'Shift_JIS')
60
- assert_equal 'Shift_JIS', doc.encoding
61
- assert n = doc.xpath('//car').first
62
-
63
- n.namespace_definitions.each do |nd|
64
- assert_equal 'UTF-8', nd.href.encoding.name
65
- assert_equal 'UTF-8', nd.prefix.encoding.name
66
- end
67
-
68
- n.namespaces.each do |k,v|
69
- assert_equal 'UTF-8', k.encoding.name
70
- assert_equal 'UTF-8', v.encoding.name
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,32 +0,0 @@
1
- # issue#560
2
-
3
- require 'helper'
4
-
5
- module Nokogiri
6
- module XML
7
- class TestNodeInheritance < Nokogiri::TestCase
8
- MyNode = Class.new Nokogiri::XML::Node
9
- def setup
10
- super
11
- @node = MyNode.new 'foo', Nokogiri::XML::Document.new
12
- @node['foo'] = 'bar'
13
- end
14
-
15
- def test_node_name
16
- assert @node.name == 'foo'
17
- end
18
-
19
- def test_node_writing_an_attribute_accessing_via_attributes
20
- assert @node.attributes['foo']
21
- end
22
-
23
- def test_node_writing_an_attribute_accessing_via_key
24
- assert @node.key? 'foo'
25
- end
26
-
27
- def test_node_writing_an_attribute_accessing_via_brackets
28
- assert @node['foo'] == 'bar'
29
- end
30
- end
31
- end
32
- end
@@ -1,661 +0,0 @@
1
- require "helper"
2
-
3
- module Nokogiri
4
- module XML
5
- class TestNodeReparenting < Nokogiri::TestCase
6
-
7
- describe "standard node reparenting behavior" do
8
- # describe "namespace handling during reparenting" do
9
- # describe "given a Node" do
10
- # describe "with a Namespace" do
11
- # it "keeps the Namespace"
12
- # end
13
- # describe "given a parent Node with a default and a non-default Namespace" do
14
- # describe "passed an Node without a namespace" do
15
- # it "inserts an Node that inherits the default Namespace"
16
- # end
17
- # describe "passed a Node with a Namespace that matches the parent's non-default Namespace" do
18
- # it "inserts a Node that inherits the matching parent Namespace"
19
- # end
20
- # end
21
- # end
22
- # describe "given a markup string" do
23
- # describe "parsed relative to the document" do
24
- # describe "with a Namespace" do
25
- # it "keeps the Namespace"
26
- # end
27
- # describe "given a parent Node with a default and a non-default Namespace" do
28
- # describe "passed an Node without a namespace" do
29
- # it "inserts an Node that inherits the default Namespace"
30
- # end
31
- # describe "passed a Node with a Namespace that matches the parent's non-default Namespace" do
32
- # it "inserts a Node that inherits the matching parent Namespace"
33
- # end
34
- # end
35
- # end
36
- # describe "parsed relative to a specific node" do
37
- # describe "with a Namespace" do
38
- # it "keeps the Namespace"
39
- # end
40
- # describe "given a parent Node with a default and a non-default Namespace" do
41
- # describe "passed an Node without a namespace" do
42
- # it "inserts an Node that inherits the default Namespace"
43
- # end
44
- # describe "passed a Node with a Namespace that matches the parent's non-default Namespace" do
45
- # it "inserts a Node that inherits the matching parent Namespace"
46
- # end
47
- # end
48
- # end
49
- # end
50
- # end
51
-
52
-
53
- before do
54
- @doc = Nokogiri::XML "<root><a1>First node</a1><a2>Second node</a2><a3>Third <bx />node</a3></root>"
55
- @doc2 = @doc.dup
56
- @fragment_string = "<b1>foo</b1><b2>bar</b2>"
57
- @fragment = Nokogiri::XML::DocumentFragment.parse @fragment_string
58
- @node_set = Nokogiri::XML("<root><b1>foo</b1><b2>bar</b2></root>").xpath("/root/node()")
59
- end
60
-
61
- {
62
- :add_child => {:target => "/root/a1", :returns_self => false, :children_tags => %w[text b1 b2]},
63
- :<< => {:target => "/root/a1", :returns_self => true, :children_tags => %w[text b1 b2]},
64
-
65
- :replace => {:target => "/root/a1/node()", :returns_self => false, :children_tags => %w[b1 b2]},
66
- :swap => {:target => "/root/a1/node()", :returns_self => true, :children_tags => %w[b1 b2]},
67
-
68
- :children= => {:target => "/root/a1", :returns_self => false, :children_tags => %w[b1 b2]},
69
- :inner_html= => {:target => "/root/a1", :returns_self => true, :children_tags => %w[b1 b2]},
70
-
71
- :add_previous_sibling => {:target => "/root/a1/text()", :returns_self => false, :children_tags => %w[b1 b2 text]},
72
- :previous= => {:target => "/root/a1/text()", :returns_self => false, :children_tags => %w[b1 b2 text]},
73
- :before => {:target => "/root/a1/text()", :returns_self => true, :children_tags => %w[b1 b2 text]},
74
-
75
- :add_next_sibling => {:target => "/root/a1/text()", :returns_self => false, :children_tags => %w[text b1 b2]},
76
- :next= => {:target => "/root/a1/text()", :returns_self => false, :children_tags => %w[text b1 b2]},
77
- :after => {:target => "/root/a1/text()", :returns_self => true, :children_tags => %w[text b1 b2]}
78
- }.each do |method, params|
79
- describe "##{method}" do
80
- describe "passed a Node" do
81
- [:current, :another].each do |which|
82
- describe "passed a Node in the #{which} document" do
83
- before do
84
- @other_doc = which == :current ? @doc : @doc2
85
- @other_node = @other_doc.at_xpath("/root/a2")
86
- end
87
-
88
- it "unlinks the Node from its previous position" do
89
- @doc.at_xpath(params[:target]).send(method, @other_node)
90
- @other_doc.at_xpath("/root/a2").must_be_nil
91
- end
92
-
93
- it "inserts the Node in the proper position" do
94
- @doc.at_xpath(params[:target]).send(method, @other_node)
95
- @doc.at_xpath("/root/a1/a2").wont_be_nil
96
- end
97
-
98
- it "returns the expected value" do
99
- sendee = @doc.at_xpath(params[:target])
100
- result = sendee.send(method, @other_node)
101
- if params[:returns_self]
102
- result.must_equal sendee
103
- else
104
- result.must_equal @other_node
105
- end
106
- end
107
- end
108
- end
109
- end
110
- describe "passed a markup string" do
111
- it "inserts the fragment roots in the proper position" do
112
- @doc.at_xpath(params[:target]).send(method, @fragment_string)
113
- @doc.xpath("/root/a1/node()").collect {|n| n.name}.must_equal params[:children_tags]
114
- end
115
-
116
- it "returns the expected value" do
117
- sendee = @doc.at_xpath(params[:target])
118
- result = sendee.send(method, @fragment_string)
119
- if params[:returns_self]
120
- result.must_equal sendee
121
- else
122
- result.must_be_kind_of Nokogiri::XML::NodeSet
123
- result.to_html.must_equal @fragment_string
124
- end
125
- end
126
- end
127
- describe "passed a fragment" do
128
- it "inserts the fragment roots in the proper position" do
129
- @doc.at_xpath(params[:target]).send(method, @fragment)
130
- @doc.xpath("/root/a1/node()").collect {|n| n.name}.must_equal params[:children_tags]
131
- end
132
- end
133
- describe "passed a document" do
134
- it "raises an exception" do
135
- proc { @doc.at_xpath("/root/a1").send(method, @doc2) }.must_raise(ArgumentError)
136
- end
137
- end
138
- describe "passed a non-Node" do
139
- it "raises an exception" do
140
- proc { @doc.at_xpath("/root/a1").send(method, 42) }.must_raise(ArgumentError)
141
- end
142
- end
143
- describe "passed a NodeSet" do
144
- it "inserts each member of the NodeSet in the proper order" do
145
- @doc.at_xpath(params[:target]).send(method, @node_set)
146
- @doc.xpath("/root/a1/node()").collect {|n| n.name}.must_equal params[:children_tags]
147
- end
148
- end
149
- end
150
- end
151
-
152
- describe "text node merging" do
153
- describe "#add_child" do
154
- it "merges the Text node with adjacent Text nodes" do
155
- @doc.at_xpath("/root/a1").add_child Nokogiri::XML::Text.new('hello', @doc)
156
- @doc.at_xpath("/root/a1/text()").content.must_equal "First nodehello"
157
- end
158
- end
159
-
160
- describe "#replace" do
161
- it "merges the Text node with adjacent Text nodes" do
162
- @doc.at_xpath("/root/a3/bx").replace Nokogiri::XML::Text.new('hello', @doc)
163
- @doc.at_xpath("/root/a3/text()").content.must_equal "Third hellonode"
164
- end
165
- end
166
- end
167
- end
168
-
169
- describe "ad hoc node reparenting behavior" do
170
- describe "#<<" do
171
- it "allows chaining" do
172
- doc = Nokogiri::XML::Document.new
173
- root = Nokogiri::XML::Element.new('root', doc)
174
- doc.root = root
175
-
176
- child1 = Nokogiri::XML::Element.new('child1', doc)
177
- child2 = Nokogiri::XML::Element.new('child2', doc)
178
-
179
- doc.root << child1 << child2
180
-
181
- assert_equal [child1, child2], doc.root.children.to_a
182
- end
183
- end
184
-
185
- describe "#add_child" do
186
- describe "given a new node with a namespace" do
187
- it "keeps the namespace" do
188
- doc = Nokogiri::XML::Document.new
189
- item = Nokogiri::XML::Element.new('item', doc)
190
- doc.root = item
191
-
192
- entry = Nokogiri::XML::Element.new('entry', doc)
193
- entry.add_namespace('tlm', 'http://tenderlovemaking.com')
194
- assert_equal 'http://tenderlovemaking.com', entry.namespaces['xmlns:tlm']
195
- item.add_child(entry)
196
- assert_equal 'http://tenderlovemaking.com', entry.namespaces['xmlns:tlm']
197
- end
198
- end
199
-
200
- describe "given the new document is empty" do
201
- it "adds the node to the new document" do
202
- doc1 = Nokogiri::XML.parse("<value>3</value>")
203
- doc2 = Nokogiri::XML::Document.new
204
- node = doc1.at_xpath("//value")
205
- node.remove
206
- doc2.add_child(node)
207
- assert_match(/<value>3<\/value>/, doc2.to_xml)
208
- end
209
- end
210
-
211
- describe "given a parent node with a default namespace" do
212
- before do
213
- @doc = Nokogiri::XML(<<-eoxml)
214
- <root xmlns="http://tenderlovemaking.com/">
215
- <first>
216
- </first>
217
- </root>
218
- eoxml
219
- end
220
-
221
- it "inserts a node that inherits the default namespace" do
222
- assert node = @doc.at('//xmlns:first')
223
- child = Nokogiri::XML::Node.new('second', @doc)
224
- node.add_child(child)
225
- assert @doc.at('//xmlns:second')
226
- end
227
-
228
- describe "and a child node was added to a new doc with the a different namespace using the same prefix" do
229
- before do
230
- @doc = Nokogiri::XML %Q{<root xmlns:bar="http://tenderlovemaking.com/"><bar:first/></root>}
231
- new_doc = Nokogiri::XML %Q{<newroot xmlns:bar="http://flavorjon.es/"/>}
232
- assert node = @doc.at("//tenderlove:first", tenderlove: "http://tenderlovemaking.com/")
233
- new_doc.root.add_child node
234
- @doc = new_doc
235
- end
236
-
237
- it "serializes the doc with the proper default namespace" do
238
- assert_match(/<bar:first\ xmlns:bar="http:\/\/tenderlovemaking.com\/"\/>/, @doc.to_xml)
239
- end
240
- end
241
-
242
- describe "and a child node was added to a new doc with the same default namespaces" do
243
- before do
244
- new_doc = Nokogiri::XML %Q{<newroot xmlns="http://tenderlovemaking.com/"/>}
245
- assert node = @doc.at("//tenderlove:first", tenderlove: "http://tenderlovemaking.com/")
246
- new_doc.root.add_child node
247
- @doc = new_doc
248
- end
249
-
250
- it "serializes the doc with the proper default namespace" do
251
- assert_match(/<first>/, @doc.to_xml)
252
- end
253
- end
254
-
255
- describe "and a child node was added to a new doc without any default namespaces" do
256
- before do
257
- new_doc = Nokogiri::XML "<newroot/>"
258
- assert node = @doc.at("//tenderlove:first", tenderlove: "http://tenderlovemaking.com/")
259
- new_doc.root.add_child node
260
- @doc = new_doc
261
- end
262
-
263
- it "serializes the doc with the proper default namespace" do
264
- assert_match(/<first xmlns=\"http:\/\/tenderlovemaking.com\/\">/, @doc.to_xml)
265
- end
266
- end
267
-
268
- describe "and a child node became the root of a new doc" do
269
- before do
270
- new_doc = Nokogiri::XML::Document.new
271
- assert node = @doc.at("//tenderlove:first", tenderlove: "http://tenderlovemaking.com/")
272
- new_doc.root = node
273
- @doc = new_doc
274
- end
275
-
276
- it "serializes the doc with the proper default namespace" do
277
- assert_match(/<first xmlns=\"http:\/\/tenderlovemaking.com\/\">/, @doc.to_xml)
278
- end
279
- end
280
- end
281
-
282
- describe "given a parent node with a default and non-default namespace" do
283
- before do
284
- @doc = Nokogiri::XML(<<-eoxml)
285
- <root xmlns="http://tenderlovemaking.com/" xmlns:foo="http://flavorjon.es/">
286
- <first>
287
- </first>
288
- </root>
289
- eoxml
290
- assert @node = @doc.at('//xmlns:first')
291
- @child = Nokogiri::XML::Node.new('second', @doc)
292
- end
293
-
294
- describe "and a child with a namespace matching the parent's default namespace" do
295
- describe "and as the default prefix" do
296
- before do
297
- @ns = @child.add_namespace(nil, 'http://tenderlovemaking.com/')
298
- @child.namespace = @ns
299
- end
300
-
301
- it "inserts a node that inherits the parent's default namespace" do
302
- @node.add_child(@child)
303
- assert reparented = @doc.at('//bar:second', "bar" => "http://tenderlovemaking.com/")
304
- assert reparented.namespace_definitions.empty?
305
- assert_equal @doc.root.namespace, reparented.namespace
306
- assert_equal(
307
- {
308
- "xmlns" => "http://tenderlovemaking.com/",
309
- "xmlns:foo" => "http://flavorjon.es/",
310
- },
311
- reparented.namespaces)
312
- end
313
- end
314
-
315
- describe "but with a different prefix" do
316
- before do
317
- @ns = @child.add_namespace("baz", 'http://tenderlovemaking.com/')
318
- @child.namespace = @ns
319
- end
320
-
321
- it "inserts a node that uses its own namespace" do
322
- @node.add_child(@child)
323
- assert reparented = @doc.at('//bar:second', "bar" => "http://tenderlovemaking.com/")
324
- assert reparented.namespace_definitions.include?(@ns)
325
- assert_equal @ns, reparented.namespace
326
- assert_equal(
327
- {
328
- "xmlns" => "http://tenderlovemaking.com/",
329
- "xmlns:foo" => "http://flavorjon.es/",
330
- "xmlns:baz" => "http://tenderlovemaking.com/",
331
- },
332
- reparented.namespaces)
333
- end
334
- end
335
- end
336
-
337
- describe "and a child with a namespace matching the parent's non-default namespace" do
338
- before do
339
- @root_ns = @doc.root.namespace_definitions.detect { |x| x.prefix == "foo" }
340
- end
341
-
342
- describe "set by #namespace=" do
343
- before do
344
- @child.namespace = @root_ns
345
- end
346
-
347
- it "inserts a node that inherits the matching parent namespace" do
348
- @node.add_child(@child)
349
- assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
350
- assert reparented.namespace_definitions.empty?
351
- assert_equal @root_ns, reparented.namespace
352
- assert_equal(
353
- {
354
- "xmlns" => "http://tenderlovemaking.com/",
355
- "xmlns:foo" => "http://flavorjon.es/",
356
- },
357
- reparented.namespaces)
358
- end
359
- end
360
-
361
- describe "with the same prefix" do
362
- before do
363
- @ns = @child.add_namespace("foo", 'http://flavorjon.es/')
364
- @child.namespace = @ns
365
- end
366
-
367
- it "inserts a node that uses the parent's namespace" do
368
- @node.add_child(@child)
369
- assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
370
- assert reparented.namespace_definitions.empty?
371
- assert_equal @root_ns, reparented.namespace
372
- assert_equal(
373
- {
374
- "xmlns" => "http://tenderlovemaking.com/",
375
- "xmlns:foo" => "http://flavorjon.es/",
376
- },
377
- reparented.namespaces)
378
- end
379
- end
380
-
381
- describe "as the default prefix" do
382
- before do
383
- @ns = @child.add_namespace(nil, 'http://flavorjon.es/')
384
- @child.namespace = @ns
385
- end
386
-
387
- it "inserts a node that keeps its namespace" do
388
- @node.add_child(@child)
389
- assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
390
- assert reparented.namespace_definitions.include?(@ns)
391
- assert_equal @ns, reparented.namespace
392
- assert_equal(
393
- {
394
- "xmlns" => "http://flavorjon.es/",
395
- "xmlns:foo" => "http://flavorjon.es/",
396
- },
397
- reparented.namespaces)
398
- end
399
- end
400
-
401
- describe "but with a different prefix" do
402
- before do
403
- @ns = @child.add_namespace('baz', 'http://flavorjon.es/')
404
- @child.namespace = @ns
405
- end
406
-
407
- it "inserts a node that keeps its namespace" do
408
- @node.add_child(@child)
409
- assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
410
- assert reparented.namespace_definitions.include?(@ns)
411
- assert_equal @ns, reparented.namespace
412
- assert_equal(
413
- {
414
- "xmlns" =>"http://tenderlovemaking.com/",
415
- "xmlns:foo" =>"http://flavorjon.es/",
416
- "xmlns:baz" =>"http://flavorjon.es/",
417
- },
418
- reparented.namespaces)
419
- end
420
- end
421
- end
422
-
423
- describe "and a child node with a default namespace not matching the parent's default namespace and a namespace matching a parent namespace but with a different prefix" do
424
- before do
425
- @ns = @child.add_namespace(nil, 'http://example.org/')
426
- @child.namespace = @ns
427
- @ns2 = @child.add_namespace('baz', 'http://tenderlovemaking.com/')
428
- end
429
-
430
- it "inserts a node that keeps its namespace" do
431
- @node.add_child(@child)
432
- assert reparented = @doc.at('//bar:second', "bar" => "http://example.org/")
433
- assert reparented.namespace_definitions.include?(@ns)
434
- assert reparented.namespace_definitions.include?(@ns2)
435
- assert_equal @ns, reparented.namespace
436
- assert_equal(
437
- {
438
- "xmlns" => "http://example.org/",
439
- "xmlns:foo" => "http://flavorjon.es/",
440
- "xmlns:baz" => "http://tenderlovemaking.com/",
441
- },
442
- reparented.namespaces)
443
- end
444
- end
445
- end
446
- end
447
-
448
- describe "#add_previous_sibling" do
449
- it "should not merge text nodes during the operation" do
450
- xml = Nokogiri::XML %Q(<root>text node</root>)
451
- replacee = xml.root.children.first
452
- replacee.add_previous_sibling "foo <p></p> bar"
453
- assert_equal "foo <p></p> bartext node", xml.root.children.to_html
454
- end
455
-
456
- it 'should remove the child node after the operation' do
457
- fragment = Nokogiri::HTML::DocumentFragment.parse("a<a>b</a>")
458
- node = fragment.children.last
459
- node.add_previous_sibling node.children
460
- assert_empty node.children, "should have no childrens"
461
- end
462
-
463
- describe "with a text node before" do
464
- it "should not defensively dup the 'before' text node" do
465
- xml = Nokogiri::XML %Q(<root>before<p></p>after</root>)
466
- pivot = xml.at_css("p")
467
- before = xml.root.children.first
468
- after = xml.root.children.last
469
- pivot.add_previous_sibling("x")
470
-
471
- assert_equal "after", after.content
472
- assert !after.parent.nil?, "unrelated node should not be affected"
473
-
474
- assert_equal "before", before.content
475
- assert !before.parent.nil?, "no need to reparent"
476
- end
477
- end
478
- end
479
-
480
- describe "#add_next_sibling" do
481
- it "should not merge text nodes during the operation" do
482
- xml = Nokogiri::XML %Q(<root>text node</root>)
483
- replacee = xml.root.children.first
484
- replacee.add_next_sibling "foo <p></p> bar"
485
- assert_equal "text nodefoo <p></p> bar", xml.root.children.to_html
486
- end
487
-
488
- it 'should append a text node before an existing non text node' do
489
- xml = Nokogiri::XML %Q(<root><p>foo</p><p>bar</p></root>)
490
- p = xml.at_css 'p'
491
- p.add_next_sibling 'a'
492
- assert_equal '<root><p>foo</p>a<p>bar</p></root>', xml.root.to_s
493
- end
494
-
495
- it 'should append a text node before an existing text node' do
496
- xml = Nokogiri::XML %Q(<root><p>foo</p>after</root>)
497
- p = xml.at_css 'p'
498
- p.add_next_sibling 'x'
499
- assert_equal '<root><p>foo</p>xafter</root>', xml.root.to_s
500
- end
501
-
502
- describe "with a text node after" do
503
- it "should not defensively dup the 'after' text node" do
504
- xml = Nokogiri::XML %Q(<root>before<p></p>after</root>)
505
- pivot = xml.at_css("p")
506
- before = xml.root.children.first
507
- after = xml.root.children.last
508
- pivot.add_next_sibling("x")
509
-
510
- assert_equal "before", before.content
511
- assert !before.parent.nil?, "unrelated node should not be affected"
512
-
513
- assert_equal "after", after.content
514
- assert !after.parent.nil?
515
- end
516
- end
517
- end
518
-
519
- describe "#replace" do
520
- describe "a text node with a text node" do
521
- it "should not merge text nodes during the operation" do
522
- xml = Nokogiri::XML %Q(<root>text node</root>)
523
- replacee = xml.root.children.first
524
- replacee.replace "new text node"
525
- assert_equal "new text node", xml.root.children.first.content
526
- end
527
- end
528
-
529
- it "can replace with a comment node" do
530
- doc = Nokogiri::XML %Q{<parent><child>text}
531
- replacee = doc.at_css("child")
532
- replacer = doc.create_comment("<b>text</b>")
533
- replacee.replace replacer
534
- assert_equal 1, doc.root.children.length
535
- assert_equal replacer, doc.root.children.first
536
- end
537
-
538
- it "can replace with a CDATA node" do
539
- doc = Nokogiri::XML %Q{<parent><child>text}
540
- replacee = doc.at_css("child")
541
- replacer = doc.create_cdata("<b>text</b>")
542
- replacee.replace replacer
543
- assert_equal 1, doc.root.children.length
544
- assert_equal replacer, doc.root.children.first
545
- end
546
-
547
- describe "when a document has a default namespace" do
548
- before do
549
- @fruits = Nokogiri::XML(<<-eoxml)
550
- <fruit xmlns="http://fruits.org">
551
- <apple />
552
- </fruit>
553
- eoxml
554
- end
555
-
556
- it "inserts a node with default namespaces" do
557
- apple = @fruits.css('apple').first
558
-
559
- orange = Nokogiri::XML::Node.new('orange', @fruits)
560
- apple.replace(orange)
561
-
562
- assert_equal orange, @fruits.css('orange').first
563
- end
564
- end
565
- end
566
-
567
- describe "unlinking a node and then reparenting it" do
568
- it "not blow up" do
569
- # see http://github.com/sparklemotion/nokogiri/issues#issue/22
570
- 10.times do
571
- begin
572
- doc = Nokogiri::XML <<-EOHTML
573
- <root>
574
- <a>
575
- <b/>
576
- <c/>
577
- </a>
578
- </root>
579
- EOHTML
580
-
581
- assert root = doc.at("root")
582
- assert a = root.at("a")
583
- assert b = a.at("b")
584
- assert c = a.at("c")
585
- a.add_next_sibling(b.unlink)
586
- c.unlink
587
- end
588
- GC.start
589
- end
590
- end
591
- end
592
-
593
- describe "replace-merging text nodes" do
594
- [
595
- ['<root>a<br/></root>', 'afoo'],
596
- ['<root>a<br/>b</root>', 'afoob'],
597
- ['<root><br/>b</root>', 'foob']
598
- ].each do |xml, result|
599
- it "doesn't blow up on #{xml}" do
600
- doc = Nokogiri::XML.parse(xml)
601
- saved_nodes = doc.root.children
602
- doc.at_xpath("/root/br").replace(Nokogiri::XML::Text.new('foo', doc))
603
- saved_nodes.each { |child| child.inspect } # try to cause a crash
604
- assert_equal result, doc.at_xpath("/root/text()").inner_text
605
- end
606
- end
607
- end
608
-
609
- describe "reparenting and preserving a reference to the original ns" do
610
- it "should not cause illegal memory access" do
611
- # this test will only cause a failure in valgrind. it
612
- # drives out the reason why we can't call xmlFreeNs in
613
- # relink_namespace and instead have to root the nsdef.
614
- doc = Nokogiri::XML '<root xmlns="http://flavorjon.es/"><envelope /></root>'
615
- elem = doc.create_element "package", {"xmlns" => "http://flavorjon.es/"}
616
- ns = elem.namespace_definitions
617
- doc.at_css("envelope").add_child elem
618
- ns.inspect
619
- end
620
- end
621
-
622
- describe "reparenting into another document" do
623
- it "correctly sets default namespace of a reparented node" do
624
- # issue described in #391
625
- # thanks to Nick Canzoneri @nickcanz for this test case!
626
- source_doc = Nokogiri::XML <<-EOX
627
- <?xml version="1.0" encoding="utf-8"?>
628
- <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
629
- <Product>
630
- <Package />
631
- <Directory Id="TARGETDIR" Name="SourceDir">
632
- <Component>
633
- <File />
634
- </Component>
635
- </Directory>
636
- </Product>
637
- </Wix>
638
- EOX
639
-
640
- dest_doc = Nokogiri::XML <<-EOX
641
- <?xml version="1.0" encoding="utf-8"?>
642
- <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
643
- <Fragment Id='MSIComponents'>
644
- <DirectoryRef Id='InstallDir'>
645
- </DirectoryRef>
646
- </Fragment>
647
- </Wix>
648
- EOX
649
-
650
- stuff = source_doc.at_css("Directory[Id='TARGETDIR']")
651
- insert_point = dest_doc.at_css("DirectoryRef[Id='InstallDir']")
652
- insert_point.children = stuff.children()
653
-
654
- assert_no_match(/default:/, insert_point.children.to_xml)
655
- assert_match(/<Component>/, insert_point.children.to_xml)
656
- end
657
- end
658
- end
659
- end
660
- end
661
- end