nokogiri 1.9.0.rc1 → 1.9.0

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nokogiri/css/parser.rb +61 -61
  3. data/lib/nokogiri/version.rb +1 -1
  4. metadata +4 -146
  5. data/.autotest +0 -22
  6. data/.cross_rubies +0 -8
  7. data/.editorconfig +0 -17
  8. data/.gemtest +0 -0
  9. data/.travis.yml +0 -63
  10. data/CHANGELOG.md +0 -1402
  11. data/CONTRIBUTING.md +0 -42
  12. data/C_CODING_STYLE.rdoc +0 -33
  13. data/Gemfile +0 -23
  14. data/Gemfile-libxml-ruby +0 -3
  15. data/Manifest.txt +0 -371
  16. data/ROADMAP.md +0 -111
  17. data/Rakefile +0 -358
  18. data/SECURITY.md +0 -19
  19. data/STANDARD_RESPONSES.md +0 -47
  20. data/Y_U_NO_GEMSPEC.md +0 -155
  21. data/appveyor.yml +0 -29
  22. data/build_all +0 -48
  23. data/patches/sort-patches-by-date +0 -25
  24. data/suppressions/README.txt +0 -1
  25. data/suppressions/nokogiri_ruby-2.supp +0 -10
  26. data/tasks/test.rb +0 -100
  27. data/test/css/test_nthiness.rb +0 -226
  28. data/test/css/test_parser.rb +0 -386
  29. data/test/css/test_tokenizer.rb +0 -215
  30. data/test/css/test_xpath_visitor.rb +0 -96
  31. data/test/decorators/test_slop.rb +0 -23
  32. data/test/files/2ch.html +0 -108
  33. data/test/files/GH_1042.html +0 -18
  34. data/test/files/address_book.rlx +0 -12
  35. data/test/files/address_book.xml +0 -10
  36. data/test/files/atom.xml +0 -344
  37. data/test/files/bar/bar.xsd +0 -4
  38. data/test/files/bogus.xml +0 -0
  39. data/test/files/dont_hurt_em_why.xml +0 -422
  40. data/test/files/encoding.html +0 -82
  41. data/test/files/encoding.xhtml +0 -84
  42. data/test/files/exslt.xml +0 -8
  43. data/test/files/exslt.xslt +0 -35
  44. data/test/files/foo/foo.xsd +0 -4
  45. data/test/files/metacharset.html +0 -10
  46. data/test/files/namespace_pressure_test.xml +0 -1684
  47. data/test/files/noencoding.html +0 -47
  48. data/test/files/po.xml +0 -32
  49. data/test/files/po.xsd +0 -66
  50. data/test/files/saml/saml20assertion_schema.xsd +0 -283
  51. data/test/files/saml/saml20protocol_schema.xsd +0 -302
  52. data/test/files/saml/xenc_schema.xsd +0 -146
  53. data/test/files/saml/xmldsig_schema.xsd +0 -318
  54. data/test/files/shift_jis.html +0 -10
  55. data/test/files/shift_jis.xml +0 -5
  56. data/test/files/shift_jis_no_charset.html +0 -9
  57. data/test/files/slow-xpath.xml +0 -25509
  58. data/test/files/snuggles.xml +0 -3
  59. data/test/files/staff.dtd +0 -10
  60. data/test/files/staff.xml +0 -59
  61. data/test/files/staff.xslt +0 -32
  62. data/test/files/test_document_url/bar.xml +0 -2
  63. data/test/files/test_document_url/document.dtd +0 -4
  64. data/test/files/test_document_url/document.xml +0 -6
  65. data/test/files/tlm.html +0 -851
  66. data/test/files/to_be_xincluded.xml +0 -2
  67. data/test/files/valid_bar.xml +0 -2
  68. data/test/files/xinclude.xml +0 -4
  69. data/test/helper.rb +0 -271
  70. data/test/html/sax/test_parser.rb +0 -168
  71. data/test/html/sax/test_parser_context.rb +0 -46
  72. data/test/html/sax/test_parser_text.rb +0 -163
  73. data/test/html/sax/test_push_parser.rb +0 -87
  74. data/test/html/test_attributes.rb +0 -85
  75. data/test/html/test_builder.rb +0 -164
  76. data/test/html/test_document.rb +0 -722
  77. data/test/html/test_document_encoding.rb +0 -143
  78. data/test/html/test_document_fragment.rb +0 -310
  79. data/test/html/test_element_description.rb +0 -105
  80. data/test/html/test_named_characters.rb +0 -14
  81. data/test/html/test_node.rb +0 -212
  82. data/test/html/test_node_encoding.rb +0 -91
  83. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
  84. data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
  85. data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
  86. data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
  87. data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
  88. data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
  89. data/test/namespaces/test_namespaces_preservation.rb +0 -31
  90. data/test/test_convert_xpath.rb +0 -135
  91. data/test/test_css_cache.rb +0 -47
  92. data/test/test_encoding_handler.rb +0 -48
  93. data/test/test_memory_leak.rb +0 -226
  94. data/test/test_nokogiri.rb +0 -138
  95. data/test/test_soap4r_sax.rb +0 -52
  96. data/test/test_xslt_transforms.rb +0 -314
  97. data/test/xml/node/test_save_options.rb +0 -28
  98. data/test/xml/node/test_subclass.rb +0 -44
  99. data/test/xml/sax/test_parser.rb +0 -402
  100. data/test/xml/sax/test_parser_context.rb +0 -115
  101. data/test/xml/sax/test_parser_text.rb +0 -202
  102. data/test/xml/sax/test_push_parser.rb +0 -265
  103. data/test/xml/test_attr.rb +0 -96
  104. data/test/xml/test_attribute_decl.rb +0 -86
  105. data/test/xml/test_builder.rb +0 -353
  106. data/test/xml/test_c14n.rb +0 -180
  107. data/test/xml/test_cdata.rb +0 -54
  108. data/test/xml/test_comment.rb +0 -40
  109. data/test/xml/test_document.rb +0 -982
  110. data/test/xml/test_document_encoding.rb +0 -31
  111. data/test/xml/test_document_fragment.rb +0 -312
  112. data/test/xml/test_dtd.rb +0 -187
  113. data/test/xml/test_dtd_encoding.rb +0 -31
  114. data/test/xml/test_element_content.rb +0 -56
  115. data/test/xml/test_element_decl.rb +0 -73
  116. data/test/xml/test_entity_decl.rb +0 -122
  117. data/test/xml/test_entity_reference.rb +0 -262
  118. data/test/xml/test_namespace.rb +0 -96
  119. data/test/xml/test_node.rb +0 -1379
  120. data/test/xml/test_node_attributes.rb +0 -115
  121. data/test/xml/test_node_encoding.rb +0 -75
  122. data/test/xml/test_node_inheritance.rb +0 -32
  123. data/test/xml/test_node_reparenting.rb +0 -661
  124. data/test/xml/test_node_set.rb +0 -828
  125. data/test/xml/test_parse_options.rb +0 -64
  126. data/test/xml/test_processing_instruction.rb +0 -30
  127. data/test/xml/test_reader.rb +0 -620
  128. data/test/xml/test_reader_encoding.rb +0 -134
  129. data/test/xml/test_relax_ng.rb +0 -60
  130. data/test/xml/test_schema.rb +0 -142
  131. data/test/xml/test_syntax_error.rb +0 -36
  132. data/test/xml/test_text.rb +0 -69
  133. data/test/xml/test_unparented_node.rb +0 -483
  134. data/test/xml/test_xinclude.rb +0 -83
  135. data/test/xml/test_xpath.rb +0 -470
  136. data/test/xslt/test_custom_functions.rb +0 -133
  137. data/test/xslt/test_exception_handling.rb +0 -37
@@ -1,48 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "helper"
4
-
5
- class TestEncodingHandler < Nokogiri::TestCase
6
- def teardown
7
- Nokogiri::EncodingHandler.clear_aliases!
8
- #Replace default aliases removed by clear_aliases!
9
- Nokogiri.install_default_aliases
10
- end
11
-
12
- def test_get
13
- assert_not_nil Nokogiri::EncodingHandler['UTF-8']
14
- assert_nil Nokogiri::EncodingHandler['alsdkjfhaldskjfh']
15
- end
16
-
17
- def test_name
18
- eh = Nokogiri::EncodingHandler['UTF-8']
19
- assert_equal "UTF-8", eh.name
20
- end
21
-
22
- def test_alias
23
- Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-18')
24
- assert_equal 'UTF-8', Nokogiri::EncodingHandler['UTF-18'].name
25
- end
26
-
27
- def test_cleanup_aliases
28
- assert_nil Nokogiri::EncodingHandler['UTF-9']
29
- Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
30
- assert_not_nil Nokogiri::EncodingHandler['UTF-9']
31
-
32
- Nokogiri::EncodingHandler.clear_aliases!
33
- assert_nil Nokogiri::EncodingHandler['UTF-9']
34
- end
35
-
36
- def test_delete
37
- assert_nil Nokogiri::EncodingHandler['UTF-9']
38
- Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
39
- assert_not_nil Nokogiri::EncodingHandler['UTF-9']
40
-
41
- Nokogiri::EncodingHandler.delete 'UTF-9'
42
- assert_nil Nokogiri::EncodingHandler['UTF-9']
43
- end
44
-
45
- def test_delete_non_existent
46
- assert_nil Nokogiri::EncodingHandler.delete('UTF-9')
47
- end
48
- end
@@ -1,226 +0,0 @@
1
- require "helper"
2
-
3
- class TestMemoryLeak < Nokogiri::TestCase
4
- def setup
5
- super
6
- @str = <<EOF
7
- <!DOCTYPE HTML>
8
- <html>
9
- <body>
10
- <br />
11
- </body>
12
- </html>
13
- EOF
14
- end
15
-
16
- #
17
- # this suite is turned off unless the env var NOKOGIRI_GC is non-nil
18
- #
19
- # to run any of these tests, do something like this on the commandline:
20
- #
21
- # $ NOKOGIRI_GC=t ruby -Ilib:test \
22
- # test/test_memory_leak.rb \
23
- # -n /test_leaking_namespace_node_strings/
24
- #
25
- # also see:
26
- #
27
- # https://github.com/sparklemotion/nokogiri/issues/1603
28
- #
29
- # which is an open issue to resurrect these tests and run them as
30
- # part of the CI pipeline.
31
- #
32
- if ENV['NOKOGIRI_GC'] # turning these off by default for now
33
- def test_dont_hurt_em_why
34
- content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
35
- ndoc = Nokogiri::XML(content)
36
- 2.times do
37
- ndoc.search('status text').first.inner_text
38
- ndoc.search('user name').first.inner_text
39
- GC.start
40
- end
41
- end
42
-
43
- class BadIO
44
- def read(*args)
45
- raise 'hell'
46
- end
47
-
48
- def write(*args)
49
- raise 'chickens'
50
- end
51
- end
52
-
53
- def test_for_mem_leak_on_io_callbacks
54
- io = File.open SNUGGLES_FILE
55
- Nokogiri::XML.parse(io)
56
-
57
- loop do
58
- Nokogiri::XML.parse(BadIO.new) rescue nil
59
- doc.write BadIO.new rescue nil
60
- end
61
- end
62
-
63
- def test_for_memory_leak
64
- begin
65
- # we don't use Dike in any tests, but requiring it has side effects
66
- # that can create memory leaks, and that's what we're testing for.
67
- require 'rubygems'
68
- require 'dike' # do not remove!
69
-
70
- count_start = count_object_space_documents
71
- xml_data = <<-EOS
72
- <test>
73
- <items>
74
- <item>abc</item>
75
- <item>1234</item>
76
- <item>Zzz</item>
77
- <items>
78
- </test>
79
- EOS
80
- 20.times do
81
- doc = Nokogiri::XML(xml_data)
82
- doc.xpath("//item")
83
- end
84
- 2.times { GC.start }
85
- count_end = count_object_space_documents
86
- assert((count_end - count_start) <= 2, "memory leak detected")
87
- rescue LoadError
88
- puts "\ndike is not installed, skipping memory leak test"
89
- end
90
- end
91
-
92
- def test_node_set_namespace_mem_leak
93
- xml = Nokogiri::XML "<foo></foo>"
94
- ctx = Nokogiri::XML::XPathContext.new(xml)
95
- loop do
96
- ctx.evaluate("//namespace::*")
97
- end
98
- end
99
-
100
- def test_leak_on_node_replace
101
- loop do
102
- doc = Nokogiri.XML("<root><foo /></root>")
103
- n = Nokogiri::XML::CDATA.new(doc, "bar")
104
- pivot = doc.root.children[0]
105
- pivot.replace(n)
106
- end
107
- end
108
-
109
- def test_sax_parser_context
110
- io = StringIO.new(@str)
111
-
112
- loop do
113
- Nokogiri::XML::SAX::ParserContext.new(@str)
114
- Nokogiri::XML::SAX::ParserContext.new(io)
115
- io.rewind
116
-
117
- Nokogiri::HTML::SAX::ParserContext.new(@str)
118
- Nokogiri::HTML::SAX::ParserContext.new(io)
119
- io.rewind
120
- end
121
- end
122
-
123
- class JumpingSaxHandler < Nokogiri::XML::SAX::Document
124
- def initialize(jumptag)
125
- @jumptag = jumptag
126
- super()
127
- end
128
-
129
- def start_element(name, attrs = [])
130
- throw @jumptag
131
- end
132
- end
133
-
134
- def test_jumping_sax_handler
135
- doc = JumpingSaxHandler.new(:foo)
136
-
137
- loop do
138
- catch(:foo) do
139
- Nokogiri::HTML::SAX::Parser.new(doc).parse(@str)
140
- end
141
- end
142
- end
143
-
144
- def test_in_context_parser_leak
145
- loop do
146
- doc = Nokogiri::XML::Document.new
147
- fragment1 = Nokogiri::XML::DocumentFragment.new(doc, '<foo/>')
148
- node = fragment1.children[0]
149
- node.parse('<bar></bar>')
150
- end
151
- end
152
-
153
- def test_in_context_parser_leak_ii
154
- loop { Nokogiri::XML('<a/>').root.parse('<b/>') }
155
- end
156
-
157
- def test_leak_on_xpath_string_function
158
- doc = Nokogiri::XML(@str)
159
- loop do
160
- doc.xpath('name(//node())')
161
- end
162
- end
163
-
164
- def test_leaking_namespace_node_strings
165
- # see https://github.com/sparklemotion/nokogiri/issues/1810 for memory leak report
166
- ns = {'xmlns' => 'http://schemas.xmlsoap.org/soap/envelope/'}
167
- 20.times do
168
- 10_000.times do
169
- Nokogiri::XML::Builder.new do |xml|
170
- xml.send 'Envelope', ns do
171
- xml.send 'Foobar', ns
172
- end
173
- end
174
- end
175
- puts MemInfo.rss
176
- end
177
- end
178
-
179
- def test_leaking_namespace_node_strings_with_prefix
180
- # see https://github.com/sparklemotion/nokogiri/issues/1810 for memory leak report
181
- ns = {'xmlns:foo' => 'http://schemas.xmlsoap.org/soap/envelope/'}
182
- 20.times do
183
- 10_000.times do
184
- Nokogiri::XML::Builder.new do |xml|
185
- xml.send 'Envelope', ns do
186
- xml.send 'Foobar', ns
187
- end
188
- end
189
- end
190
- puts MemInfo.rss
191
- end
192
- end
193
-
194
- def test_leaking_dtd_nodes_after_internal_subset_removal
195
- # see https://github.com/sparklemotion/nokogiri/issues/1784
196
- 100_000.times do |i|
197
- doc = Nokogiri::HTML::Document.new
198
- doc.internal_subset.remove
199
- puts MemInfo.rss if (i % 1000 == 0)
200
- end
201
- end
202
- end # if NOKOGIRI_GC
203
-
204
- module MemInfo
205
- # from https://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage
206
- # this is only going to work on linux
207
- PAGE_SIZE = `getconf PAGESIZE`.chomp.to_i rescue 4096
208
- STATM_PATH = "/proc/#{Process.pid}/statm"
209
- STATM_FOUND = File.exist?(STATM_PATH)
210
-
211
- def self.rss
212
- if STATM_FOUND
213
- return (File.read(STATM_PATH).split(' ')[1].to_i * PAGE_SIZE) / 1024
214
- end
215
- return 0
216
- end
217
- end
218
-
219
- private
220
-
221
- def count_object_space_documents
222
- count = 0
223
- ObjectSpace.each_object {|j| count += 1 if j.is_a?(Nokogiri::XML::Document) }
224
- count
225
- end
226
- end
@@ -1,138 +0,0 @@
1
- require "helper"
2
-
3
- class TestNokogiri < Nokogiri::TestCase
4
- def test_versions
5
- version_match = /\d+\.\d+\.\d+/
6
- assert_match version_match, Nokogiri::VERSION
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
13
- assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
14
-
15
- assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
16
- assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
17
-
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
25
- end
26
-
27
- def test_libxml_iconv
28
- assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
29
- end
30
-
31
- def test_parse_with_io
32
- doc = Nokogiri.parse(
33
- StringIO.new("<html><head><title></title><body></body></html>")
34
- )
35
- assert_instance_of Nokogiri::HTML::Document, doc
36
- end
37
-
38
- def test_xml?
39
- doc = Nokogiri.parse(File.read(XML_FILE))
40
- assert doc.xml?
41
- assert !doc.html?
42
- end
43
-
44
- def test_atom_is_xml?
45
- doc = Nokogiri.parse(File.read(XML_ATOM_FILE))
46
- assert doc.xml?
47
- assert !doc.html?
48
- end
49
-
50
- def test_html?
51
- doc = Nokogiri.parse(File.read(HTML_FILE))
52
- assert !doc.xml?
53
- assert doc.html?
54
- end
55
-
56
- def test_nokogiri_method_with_html
57
- doc1 = Nokogiri(File.read(HTML_FILE))
58
- doc2 = Nokogiri.parse(File.read(HTML_FILE))
59
- assert_equal doc1.serialize, doc2.serialize
60
- end
61
-
62
- def test_nokogiri_method_with_block
63
- doc = Nokogiri { b "bold tag" }
64
- assert_equal('<b>bold tag</b>', doc.to_html.chomp)
65
- end
66
-
67
- def test_make_with_html
68
- doc = Nokogiri.make("<b>bold tag</b>")
69
- assert_equal('<b>bold tag</b>', doc.to_html.chomp)
70
- end
71
-
72
- def test_make_with_block
73
- doc = Nokogiri.make { b "bold tag" }
74
- assert_equal('<b>bold tag</b>', doc.to_html.chomp)
75
- end
76
-
77
- SLOP_HTML = <<-END
78
- <html>
79
- <body>
80
- <ul>
81
- <li class='red'>one</li>
82
- <li class='blue'>two</li>
83
- </ul>
84
- <div>
85
- one
86
- <div>div two</div>
87
- </div>
88
- </body>
89
- </html>
90
- END
91
-
92
- def test_slop_css
93
- doc = Nokogiri::Slop(<<-eohtml)
94
- <html>
95
- <body>
96
- <div>
97
- one
98
- <div class='foo'>
99
- div two
100
- <div class='foo'>
101
- div three
102
- </div>
103
- </div>
104
- </div>
105
- </body>
106
- </html>
107
- eohtml
108
- assert_equal "div", doc.html.body.div.div('.foo').name
109
- end
110
-
111
- def test_slop
112
- doc = Nokogiri::Slop(SLOP_HTML)
113
-
114
- assert_equal "one", doc.html.body.ul.li.first.text
115
- assert_equal "two", doc.html.body.ul.li(".blue").text
116
- assert_equal "div two", doc.html.body.div.div.text
117
-
118
- assert_equal "two", doc.html.body.ul.li(:css => ".blue").text
119
-
120
- assert_equal "two", doc.html.body.ul.li(:xpath => "position()=2").text
121
- assert_equal "one", doc.html.body.ul.li(:xpath => ["contains(text(),'o')"]).first.text
122
- assert_equal "two", doc.html.body.ul.li(:xpath => ["contains(text(),'o')","contains(text(),'t')"]).text
123
-
124
- assert_raise(NoMethodError) { doc.nonexistent }
125
- end
126
-
127
- def test_slop_decorator
128
- doc = Nokogiri(SLOP_HTML)
129
- assert !doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
130
-
131
- doc.slop!
132
- assert doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
133
-
134
- doc.slop!
135
- assert_equal 1, doc.decorators(Nokogiri::XML::Node).select { |d| d == Nokogiri::Decorators::Slop }.size
136
- end
137
-
138
- end
@@ -1,52 +0,0 @@
1
- require "helper"
2
-
3
- module XSD
4
- module XMLParser
5
- class Parser
6
- @factory_added = nil
7
-
8
- class << self; attr_reader :factory_added; end
9
-
10
- def self.add_factory o
11
- @factory_added = o
12
- end
13
-
14
- def initialize *args
15
- @charset = nil
16
- end
17
-
18
- def characters foo
19
- end
20
-
21
- def start_element *args
22
- end
23
-
24
- def end_element *args
25
- end
26
- end
27
- end
28
- end
29
-
30
- require 'xsd/xmlparser/nokogiri'
31
-
32
- class TestSoap4rSax < Nokogiri::TestCase
33
- def test_factory_added
34
- assert_equal XSD::XMLParser::Nokogiri, XSD::XMLParser::Nokogiri.factory_added
35
- end
36
-
37
- def test_parse
38
- o = Class.new(::XSD::XMLParser::Nokogiri) do
39
- attr_accessor :element_started
40
- def initialize *args
41
- super
42
- @element_started = false
43
- end
44
-
45
- def start_element *args
46
- @element_started = true
47
- end
48
- end.new 'foo'
49
- o.do_parse '<?xml version="1.0" ?><root xmlns="http://example.com/"/>'
50
- assert o.element_started, 'element started'
51
- end
52
- end