nokogiri 1.12.5 → 1.13.8

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +9 -7
  4. data/bin/nokogiri +63 -50
  5. data/dependencies.yml +13 -64
  6. data/ext/nokogiri/extconf.rb +66 -44
  7. data/ext/nokogiri/gumbo.c +1 -1
  8. data/ext/nokogiri/html4_sax_parser_context.c +2 -3
  9. data/ext/nokogiri/nokogiri.h +8 -0
  10. data/ext/nokogiri/xml_attr.c +2 -2
  11. data/ext/nokogiri/xml_attribute_decl.c +3 -3
  12. data/ext/nokogiri/xml_cdata.c +1 -1
  13. data/ext/nokogiri/xml_document.c +36 -36
  14. data/ext/nokogiri/xml_document_fragment.c +0 -2
  15. data/ext/nokogiri/xml_dtd.c +10 -10
  16. data/ext/nokogiri/xml_element_decl.c +3 -3
  17. data/ext/nokogiri/xml_encoding_handler.c +25 -11
  18. data/ext/nokogiri/xml_entity_decl.c +5 -5
  19. data/ext/nokogiri/xml_node.c +707 -381
  20. data/ext/nokogiri/xml_node_set.c +4 -4
  21. data/ext/nokogiri/xml_reader.c +88 -11
  22. data/ext/nokogiri/xml_sax_parser_context.c +10 -3
  23. data/ext/nokogiri/xml_schema.c +3 -3
  24. data/ext/nokogiri/xml_text.c +1 -1
  25. data/ext/nokogiri/xml_xpath_context.c +73 -50
  26. data/ext/nokogiri/xslt_stylesheet.c +107 -9
  27. data/gumbo-parser/src/parser.c +0 -11
  28. data/lib/nokogiri/class_resolver.rb +67 -0
  29. data/lib/nokogiri/css/node.rb +9 -8
  30. data/lib/nokogiri/css/parser.rb +360 -341
  31. data/lib/nokogiri/css/parser.y +249 -244
  32. data/lib/nokogiri/css/parser_extras.rb +22 -20
  33. data/lib/nokogiri/css/syntax_error.rb +1 -0
  34. data/lib/nokogiri/css/tokenizer.rb +4 -3
  35. data/lib/nokogiri/css/tokenizer.rex +3 -2
  36. data/lib/nokogiri/css/xpath_visitor.rb +179 -82
  37. data/lib/nokogiri/css.rb +38 -6
  38. data/lib/nokogiri/decorators/slop.rb +8 -7
  39. data/lib/nokogiri/extension.rb +1 -1
  40. data/lib/nokogiri/gumbo.rb +1 -0
  41. data/lib/nokogiri/html.rb +16 -10
  42. data/lib/nokogiri/html4/builder.rb +1 -0
  43. data/lib/nokogiri/html4/document.rb +88 -77
  44. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  45. data/lib/nokogiri/html4/element_description.rb +1 -0
  46. data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
  47. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  48. data/lib/nokogiri/html4/sax/parser.rb +5 -2
  49. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  50. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  51. data/lib/nokogiri/html4.rb +11 -5
  52. data/lib/nokogiri/html5/document.rb +27 -10
  53. data/lib/nokogiri/html5/document_fragment.rb +5 -2
  54. data/lib/nokogiri/html5/node.rb +10 -3
  55. data/lib/nokogiri/html5.rb +69 -64
  56. data/lib/nokogiri/jruby/dependencies.rb +10 -9
  57. data/lib/nokogiri/syntax_error.rb +1 -0
  58. data/lib/nokogiri/version/constant.rb +2 -1
  59. data/lib/nokogiri/version/info.rb +20 -13
  60. data/lib/nokogiri/version.rb +1 -0
  61. data/lib/nokogiri/xml/attr.rb +5 -3
  62. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  63. data/lib/nokogiri/xml/builder.rb +34 -32
  64. data/lib/nokogiri/xml/cdata.rb +2 -1
  65. data/lib/nokogiri/xml/character_data.rb +1 -0
  66. data/lib/nokogiri/xml/document.rb +144 -103
  67. data/lib/nokogiri/xml/document_fragment.rb +41 -38
  68. data/lib/nokogiri/xml/dtd.rb +3 -2
  69. data/lib/nokogiri/xml/element_content.rb +1 -0
  70. data/lib/nokogiri/xml/element_decl.rb +2 -1
  71. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  72. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  73. data/lib/nokogiri/xml/namespace.rb +2 -0
  74. data/lib/nokogiri/xml/node/save_options.rb +8 -4
  75. data/lib/nokogiri/xml/node.rb +521 -351
  76. data/lib/nokogiri/xml/node_set.rb +50 -54
  77. data/lib/nokogiri/xml/notation.rb +12 -0
  78. data/lib/nokogiri/xml/parse_options.rb +12 -7
  79. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  80. data/lib/nokogiri/xml/pp/node.rb +24 -26
  81. data/lib/nokogiri/xml/pp.rb +1 -0
  82. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  83. data/lib/nokogiri/xml/reader.rb +20 -24
  84. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  85. data/lib/nokogiri/xml/sax/document.rb +20 -19
  86. data/lib/nokogiri/xml/sax/parser.rb +37 -34
  87. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  88. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  89. data/lib/nokogiri/xml/sax.rb +1 -0
  90. data/lib/nokogiri/xml/schema.rb +7 -6
  91. data/lib/nokogiri/xml/searchable.rb +93 -62
  92. data/lib/nokogiri/xml/syntax_error.rb +5 -4
  93. data/lib/nokogiri/xml/text.rb +1 -0
  94. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  95. data/lib/nokogiri/xml/xpath.rb +12 -0
  96. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  97. data/lib/nokogiri/xml.rb +4 -3
  98. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  99. data/lib/nokogiri/xslt.rb +21 -13
  100. data/lib/nokogiri.rb +19 -16
  101. data/lib/xsd/xmlparser/nokogiri.rb +25 -24
  102. data/patches/libxml2/0004-use-glibc-strlen.patch +3 -3
  103. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2443 -1914
  104. data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +61 -0
  105. data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
  106. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
  107. data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
  108. data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
  109. metadata +104 -32
  110. data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
  111. data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
  112. data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
  113. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "singleton"
3
4
  require "shellwords"
4
5
 
@@ -102,8 +103,8 @@ module Nokogiri
102
103
  ldflags = []
103
104
 
104
105
  if libxml2_using_packaged?
105
- cppflags << "-I#{File.join(header_directory, 'include').shellescape}"
106
- cppflags << "-I#{File.join(header_directory, 'include/libxml2').shellescape}"
106
+ cppflags << "-I#{File.join(header_directory, "include").shellescape}"
107
+ cppflags << "-I#{File.join(header_directory, "include/libxml2").shellescape}"
107
108
 
108
109
  if windows?
109
110
  # on windows, nokogumbo needs to link against nokogiri.so to resolve symbols. see #2167
@@ -176,13 +177,9 @@ module Nokogiri
176
177
  end
177
178
 
178
179
  def to_markdown
179
- begin
180
- require "psych"
181
- rescue LoadError
182
- end
183
180
  require "yaml"
184
181
  "# Nokogiri (#{Nokogiri::VERSION})\n" +
185
- YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
182
+ YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
186
183
  end
187
184
 
188
185
  instance.warnings.each do |warning|
@@ -190,26 +187,36 @@ module Nokogiri
190
187
  end
191
188
  end
192
189
 
193
- def self.uses_libxml?(requirement = nil) # :nodoc:
190
+ # :nodoc:
191
+ def self.uses_libxml?(requirement = nil)
194
192
  return false unless VersionInfo.instance.libxml2?
195
193
  return true unless requirement
194
+
196
195
  Gem::Requirement.new(requirement).satisfied_by?(VersionInfo.instance.loaded_libxml_version)
197
196
  end
198
197
 
198
+ # :nodoc:
199
199
  def self.uses_gumbo?
200
200
  uses_libxml? # TODO: replace with Gumbo functionality
201
201
  end
202
202
 
203
- def self.jruby? # :nodoc:
203
+ # :nodoc:
204
+ def self.jruby?
204
205
  VersionInfo.instance.jruby?
205
206
  end
206
207
 
207
- # Ensure constants used in this file are loaded - see #1896
208
- if Nokogiri.jruby?
209
- require_relative "../jruby/dependencies"
208
+ # :nodoc:
209
+ def self.libxml2_patches
210
+ if VersionInfo.instance.libxml2_using_packaged?
211
+ Nokogiri::VERSION_INFO["libxml"]["patches"]
212
+ else
213
+ []
214
+ end
210
215
  end
216
+
217
+ require_relative "../jruby/dependencies" if Nokogiri.jruby?
211
218
  require_relative "../extension"
212
219
 
213
- # More complete version information about libxml
220
+ # Detailed version info about Nokogiri and the installed extension dependencies.
214
221
  VERSION_INFO = VersionInfo.instance.to_hash
215
222
  end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "version/constant"
3
4
  require_relative "version/info"
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class Attr < Node
5
- alias :value :content
6
- alias :to_s :content
7
- alias :content= :value=
6
+ alias_method :value, :content
7
+ alias_method :to_s, :content
8
+ alias_method :content=, :value=
8
9
 
9
10
  private
11
+
10
12
  def inspect_attributes
11
13
  [:name, :namespace, :value]
12
14
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  ###
@@ -12,7 +13,7 @@ module Nokogiri
12
13
  undef_method :line if method_defined?(:line)
13
14
 
14
15
  def inspect
15
- "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
16
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{to_s.inspect}>"
16
17
  end
17
18
  end
18
19
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  ###
@@ -261,7 +262,9 @@ module Nokogiri
261
262
  # </root>
262
263
  #
263
264
  class Builder
264
- DEFAULT_DOCUMENT_OPTIONS = {namespace_inheritance: true}
265
+ include Nokogiri::ClassResolver
266
+
267
+ DEFAULT_DOCUMENT_OPTIONS = { namespace_inheritance: true }
265
268
 
266
269
  # The current Document object being built
267
270
  attr_accessor :doc
@@ -306,13 +309,7 @@ module Nokogiri
306
309
  @doc = root.document
307
310
  @parent = root
308
311
  else
309
- klassname = "::" + (self.class.name.split("::")[0..-2] + ["Document"]).join("::")
310
- klass = begin
311
- Object.const_get(klassname)
312
- rescue NameError
313
- Nokogiri::XML::Document
314
- end
315
- @parent = @doc = klass.new
312
+ @parent = @doc = related_class("Document").new
316
313
  end
317
314
 
318
315
  @context = nil
@@ -324,7 +321,7 @@ module Nokogiri
324
321
  @doc.send(:"#{k}=", v)
325
322
  end
326
323
 
327
- return unless block_given?
324
+ return unless block
328
325
 
329
326
  @arity = block.arity
330
327
  if @arity <= 0
@@ -340,19 +337,19 @@ module Nokogiri
340
337
  ###
341
338
  # Create a Text Node with content of +string+
342
339
  def text(string)
343
- insert @doc.create_text_node(string)
340
+ insert(@doc.create_text_node(string))
344
341
  end
345
342
 
346
343
  ###
347
344
  # Create a CDATA Node with content of +string+
348
345
  def cdata(string)
349
- insert doc.create_cdata(string)
346
+ insert(doc.create_cdata(string))
350
347
  end
351
348
 
352
349
  ###
353
350
  # Create a Comment Node with content of +string+
354
351
  def comment(string)
355
- insert doc.create_comment(string)
352
+ insert(doc.create_comment(string))
356
353
  end
357
354
 
358
355
  ###
@@ -366,12 +363,13 @@ module Nokogiri
366
363
 
367
364
  @parent.ancestors.each do |a|
368
365
  next if a == doc
366
+
369
367
  @ns = a.namespace_definitions.find { |x| x.prefix == ns.to_s }
370
368
  return self if @ns
371
369
  end
372
370
 
373
- @ns = { :pending => ns.to_s }
374
- return self
371
+ @ns = { pending: ns.to_s }
372
+ self
375
373
  end
376
374
 
377
375
  ###
@@ -379,7 +377,7 @@ module Nokogiri
379
377
  def to_xml(*args)
380
378
  if Nokogiri.jruby?
381
379
  options = args.first.is_a?(Hash) ? args.shift : {}
382
- if !options[:save_with]
380
+ unless options[:save_with]
383
381
  options[:save_with] = Node::SaveOptions::AS_BUILDER
384
382
  end
385
383
  args.insert(0, options)
@@ -394,22 +392,23 @@ module Nokogiri
394
392
  end
395
393
 
396
394
  def method_missing(method, *args, &block) # :nodoc:
397
- if @context && @context.respond_to?(method)
395
+ if @context&.respond_to?(method)
398
396
  @context.send(method, *args, &block)
399
397
  else
400
- node = @doc.create_element(method.to_s.sub(/[_!]$/, ""), *args) { |n|
398
+ node = @doc.create_element(method.to_s.sub(/[_!]$/, ""), *args) do |n|
401
399
  # Set up the namespace
402
- if @ns.is_a? Nokogiri::XML::Namespace
400
+ if @ns.is_a?(Nokogiri::XML::Namespace)
403
401
  n.namespace = @ns
404
402
  @ns = nil
405
403
  end
406
- }
404
+ end
407
405
 
408
- if @ns.is_a? Hash
406
+ if @ns.is_a?(Hash)
409
407
  node.namespace = node.namespace_definitions.find { |x| x.prefix == @ns[:pending] }
410
408
  if node.namespace.nil?
411
409
  raise ArgumentError, "Namespace #{@ns[:pending]} has not been defined"
412
410
  end
411
+
413
412
  @ns = nil
414
413
  end
415
414
 
@@ -423,16 +422,19 @@ module Nokogiri
423
422
  # Insert +node+ as a child of the current Node
424
423
  def insert(node, &block)
425
424
  node = @parent.add_child(node)
426
- if block_given?
427
- old_parent = @parent
428
- @parent = node
429
- @arity ||= block.arity
430
- if @arity <= 0
431
- instance_eval(&block)
432
- else
433
- block.call(self)
425
+ if block
426
+ begin
427
+ old_parent = @parent
428
+ @parent = node
429
+ @arity ||= block.arity
430
+ if @arity <= 0
431
+ instance_eval(&block)
432
+ else
433
+ yield(self)
434
+ end
435
+ ensure
436
+ @parent = old_parent
434
437
  end
435
- @parent = old_parent
436
438
  end
437
439
  NodeBuilder.new(node, self)
438
440
  end
@@ -455,10 +457,10 @@ module Nokogiri
455
457
  opts = args.last.is_a?(Hash) ? args.pop : {}
456
458
  case method.to_s
457
459
  when /^(.*)!$/
458
- @node["id"] = $1
460
+ @node["id"] = Regexp.last_match(1)
459
461
  @node.content = args.first if args.first
460
462
  when /^(.*)=/
461
- @node[$1] = args.first
463
+ @node[Regexp.last_match(1)] = args.first
462
464
  else
463
465
  @node["class"] =
464
466
  ((@node["class"] || "").split(/\s/) + [method.to_s]).join(" ")
@@ -470,7 +472,7 @@ module Nokogiri
470
472
  @node[k.to_s] = ((@node[k.to_s] || "").split(/\s/) + [v]).join(" ")
471
473
  end
472
474
 
473
- if block_given?
475
+ if block
474
476
  old_parent = @doc_builder.parent
475
477
  @doc_builder.parent = @node
476
478
  value = @doc_builder.instance_eval(&block)
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class CDATA < Nokogiri::XML::Text
5
6
  ###
6
7
  # Get the name of this CDATA node
7
8
  def name
8
- '#cdata-section'
9
+ "#cdata-section"
9
10
  end
10
11
  end
11
12
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class CharacterData < Nokogiri::XML::Node