nokogiri 1.11.0.rc4 → 1.11.3

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +12 -12
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/ext/nokogiri/depend +34 -474
  7. data/ext/nokogiri/extconf.rb +270 -183
  8. data/ext/nokogiri/html_document.c +10 -15
  9. data/ext/nokogiri/html_element_description.c +84 -71
  10. data/ext/nokogiri/html_entity_lookup.c +21 -16
  11. data/ext/nokogiri/html_sax_parser_context.c +67 -64
  12. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  13. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  14. data/ext/nokogiri/nokogiri.c +171 -60
  15. data/ext/nokogiri/nokogiri.h +158 -75
  16. data/ext/nokogiri/test_global_handlers.c +40 -0
  17. data/ext/nokogiri/xml_attr.c +15 -15
  18. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  19. data/ext/nokogiri/xml_cdata.c +13 -18
  20. data/ext/nokogiri/xml_comment.c +19 -26
  21. data/ext/nokogiri/xml_document.c +246 -188
  22. data/ext/nokogiri/xml_document_fragment.c +13 -15
  23. data/ext/nokogiri/xml_dtd.c +54 -48
  24. data/ext/nokogiri/xml_element_content.c +30 -27
  25. data/ext/nokogiri/xml_element_decl.c +22 -22
  26. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  27. data/ext/nokogiri/xml_entity_decl.c +32 -30
  28. data/ext/nokogiri/xml_entity_reference.c +16 -18
  29. data/ext/nokogiri/xml_namespace.c +56 -49
  30. data/ext/nokogiri/xml_node.c +371 -320
  31. data/ext/nokogiri/xml_node_set.c +168 -156
  32. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  33. data/ext/nokogiri/xml_reader.c +191 -157
  34. data/ext/nokogiri/xml_relax_ng.c +29 -23
  35. data/ext/nokogiri/xml_sax_parser.c +117 -112
  36. data/ext/nokogiri/xml_sax_parser_context.c +101 -84
  37. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  38. data/ext/nokogiri/xml_schema.c +48 -42
  39. data/ext/nokogiri/xml_syntax_error.c +42 -21
  40. data/ext/nokogiri/xml_text.c +13 -17
  41. data/ext/nokogiri/xml_xpath_context.c +134 -127
  42. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  43. data/lib/nokogiri/css/parser.rb +1 -1
  44. data/lib/nokogiri/extension.rb +26 -0
  45. data/lib/nokogiri/html/document_fragment.rb +15 -15
  46. data/lib/nokogiri/version/constant.rb +1 -1
  47. data/lib/nokogiri/version/info.rb +31 -8
  48. data/lib/nokogiri/xml/document.rb +74 -28
  49. data/lib/nokogiri/xml/node.rb +39 -42
  50. data/lib/nokogiri/xml/reader.rb +2 -9
  51. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  52. data/lib/nokogiri/xml/xpath.rb +1 -3
  53. data/lib/nokogiri.rb +2 -6
  54. data/patches/libxml2/0009-avoid-isnan-isinf.patch +81 -0
  55. data/patches/libxml2/0010-parser.c-shrink-the-input-buffer-when-appropriate.patch +70 -0
  56. data/patches/libxml2/0011-update-automake-files-for-arm64.patch +2511 -0
  57. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
  58. metadata +66 -160
  59. data/ext/nokogiri/html_document.h +0 -10
  60. data/ext/nokogiri/html_element_description.h +0 -10
  61. data/ext/nokogiri/html_entity_lookup.h +0 -8
  62. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  63. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  64. data/ext/nokogiri/xml_attr.h +0 -9
  65. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  66. data/ext/nokogiri/xml_cdata.h +0 -9
  67. data/ext/nokogiri/xml_comment.h +0 -9
  68. data/ext/nokogiri/xml_document.h +0 -23
  69. data/ext/nokogiri/xml_document_fragment.h +0 -10
  70. data/ext/nokogiri/xml_dtd.h +0 -10
  71. data/ext/nokogiri/xml_element_content.h +0 -10
  72. data/ext/nokogiri/xml_element_decl.h +0 -9
  73. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  74. data/ext/nokogiri/xml_entity_decl.h +0 -10
  75. data/ext/nokogiri/xml_entity_reference.h +0 -9
  76. data/ext/nokogiri/xml_io.c +0 -63
  77. data/ext/nokogiri/xml_io.h +0 -11
  78. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  79. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  80. data/ext/nokogiri/xml_namespace.h +0 -14
  81. data/ext/nokogiri/xml_node.h +0 -13
  82. data/ext/nokogiri/xml_node_set.h +0 -12
  83. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  84. data/ext/nokogiri/xml_reader.h +0 -10
  85. data/ext/nokogiri/xml_relax_ng.h +0 -9
  86. data/ext/nokogiri/xml_sax_parser.h +0 -39
  87. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  88. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  89. data/ext/nokogiri/xml_schema.h +0 -9
  90. data/ext/nokogiri/xml_syntax_error.h +0 -13
  91. data/ext/nokogiri/xml_text.h +0 -9
  92. data/ext/nokogiri/xml_xpath_context.h +0 -10
  93. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
@@ -13,11 +14,12 @@ module Nokogiri
13
14
  # Nokogiri::XML::Searchable#xpath
14
15
  #
15
16
  class Document < Nokogiri::XML::Node
16
- # I'm ignoring unicode characters here.
17
- # See http://www.w3.org/TR/REC-xml-names/#ns-decl for more details.
17
+ # See http://www.w3.org/TR/REC-xml-names/#ns-decl for more details. Note that we're not
18
+ # attempting to handle unicode characters partly because libxml2 doesn't handle unicode
19
+ # characters in NCNAMEs.
18
20
  NCNAME_START_CHAR = "A-Za-z_"
19
- NCNAME_CHAR = NCNAME_START_CHAR + "\\-.0-9"
20
- NCNAME_RE = /^xmlns(:[#{NCNAME_START_CHAR}][#{NCNAME_CHAR}]*)?$/
21
+ NCNAME_CHAR = NCNAME_START_CHAR + "\\-\\.0-9"
22
+ NCNAME_RE = /^xmlns(?::([#{NCNAME_START_CHAR}][#{NCNAME_CHAR}]*))?$/
21
23
 
22
24
  ##
23
25
  # Parse an XML file.
@@ -79,6 +81,35 @@ module Nokogiri
79
81
  return doc
80
82
  end
81
83
 
84
+ ##
85
+ # @!method wrap(java_document)
86
+ # @!scope class
87
+ #
88
+ # Create a {Document} using an existing Java DOM document object.
89
+ #
90
+ # The returned {Document} shares the same underlying data structure as the Java object, so
91
+ # changes in one are reflected in the other.
92
+ #
93
+ # @param java_document [Java::OrgW3cDom::Document]
94
+ # @return [Nokogiri::XML::Document]
95
+ # @note This method is only available when running JRuby.
96
+ # @note The class +Java::OrgW3cDom::Document+ is also accessible as +org.w3c.dom.Document+.
97
+ # @see #to_java
98
+
99
+ ##
100
+ # @!method to_java()
101
+ #
102
+ # Returns the underlying Java DOM document object for the {Document}.
103
+ #
104
+ # The returned Java object shares the same underlying data structure as the {Document}, so
105
+ # changes in one are reflected in the other.
106
+ #
107
+ # @return [Java::OrgW3cDom::Document]
108
+ # @note This method is only available when running JRuby.
109
+ # @note The class +Java::OrgW3cDom::Document+ is also accessible as +org.w3c.dom.Document+.
110
+ # @see .wrap
111
+
112
+
82
113
  # A list of Nokogiri::XML::SyntaxError found when parsing a document
83
114
  attr_accessor :errors
84
115
 
@@ -88,33 +119,58 @@ module Nokogiri
88
119
  end
89
120
 
90
121
  ##
91
- # Create an element with +name+, and optionally setting the content and attributes.
122
+ # Create a new +Element+ with +name+ sharing GC lifecycle with the document, optionally
123
+ # setting contents or attributes.
124
+ #
125
+ # Arguments may be passed to initialize the element:
126
+ # - a +Hash+ argument will be used to set attributes
127
+ # - a non-Hash object that responds to +#to_s+ will be used to set the new node's contents
92
128
  #
93
- # doc.create_element "div" # <div></div>
94
- # doc.create_element "div", :class => "container" # <div class='container'></div>
95
- # doc.create_element "div", "contents" # <div>contents</div>
96
- # doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
97
- # doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
129
+ # A block may be passed to mutate the node.
98
130
  #
99
- def create_element name, *args, &block
131
+ # @param name [String]
132
+ # @param contents_or_attrs [#to_s,Hash]
133
+ # @yieldparam node [Nokogiri::XML::Element]
134
+ # @return [Nokogiri::XML::Element]
135
+ #
136
+ # @example An empty element without attributes
137
+ # doc.create_element("div")
138
+ # # => <div></div>
139
+ #
140
+ # @example An element with contents
141
+ # doc.create_element("div", "contents")
142
+ # # => <div>contents</div>
143
+ #
144
+ # @example An element with attributes
145
+ # doc.create_element("div", {"class" => "container"})
146
+ # # => <div class='container'></div>
147
+ #
148
+ # @example An element with contents and attributes
149
+ # doc.create_element("div", "contents", {"class" => "container"})
150
+ # # => <div class='container'>contents</div>
151
+ #
152
+ # @example Passing a block to mutate the element
153
+ # doc.create_element("div") { |node| node["class"] = "blue" if before_noon? }
154
+ #
155
+ def create_element(name, *contents_or_attrs, &block)
100
156
  elm = Nokogiri::XML::Element.new(name, self, &block)
101
- args.each do |arg|
157
+ contents_or_attrs.each do |arg|
102
158
  case arg
103
159
  when Hash
104
- arg.each { |k,v|
160
+ arg.each do |k, v|
105
161
  key = k.to_s
106
162
  if key =~ NCNAME_RE
107
- ns_name = key.split(":", 2)[1]
108
- elm.add_namespace_definition ns_name, v
163
+ ns_name = Regexp.last_match(1)
164
+ elm.add_namespace_definition(ns_name, v)
109
165
  else
110
166
  elm[k.to_s] = v.to_s
111
167
  end
112
- }
168
+ end
113
169
  else
114
170
  elm.content = arg
115
171
  end
116
172
  end
117
- if ns = elm.namespace_definitions.find { |n| n.prefix.nil? or n.prefix == '' }
173
+ if ns = elm.namespace_definitions.find { |n| n.prefix.nil? || (n.prefix == '') }
118
174
  elm.namespace = ns
119
175
  end
120
176
  elm
@@ -262,24 +318,14 @@ module Nokogiri
262
318
  end
263
319
  alias :<< :add_child
264
320
 
265
- ##
266
- # +JRuby+
267
- # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
268
- def self.wrap(document) end if false # native-ext provides Document.wrap
269
-
270
- ##
271
- # +JRuby+
272
- # Returns Java's org.w3c.dom.document of this Document.
273
- def to_java; end if false # JRuby provides #to_java
274
-
275
321
  private
322
+
276
323
  def self.empty_doc? string_or_io
277
324
  string_or_io.nil? ||
278
325
  (string_or_io.respond_to?(:empty?) && string_or_io.empty?) ||
279
326
  (string_or_io.respond_to?(:eof?) && string_or_io.eof?)
280
327
  end
281
328
 
282
- # @private
283
329
  IMPLIED_XPATH_CONTEXTS = [ '//'.freeze ].freeze # :nodoc:
284
330
 
285
331
  def inspect_attributes
@@ -5,64 +5,54 @@ require "nokogiri/xml/node/save_options"
5
5
 
6
6
  module Nokogiri
7
7
  module XML
8
- ####
9
- # Nokogiri::XML::Node is your window to the fun filled world of dealing
10
- # with XML and HTML tags. A Nokogiri::XML::Node may be treated similarly
11
- # to a hash with regard to attributes. For example (from irb):
8
+ ##
9
+ # {Nokogiri::XML::Node} is your window to the fun filled world of dealing with XML and HTML
10
+ # tags. A {Nokogiri::XML::Node} may be treated similarly to a hash with regard to attributes. For
11
+ # example:
12
12
  #
13
- # irb(main):004:0> node
14
- # => <a href="#foo" id="link">link</a>
15
- # irb(main):005:0> node['href']
16
- # => "#foo"
17
- # irb(main):006:0> node.keys
18
- # => ["href", "id"]
19
- # irb(main):007:0> node.values
20
- # => ["#foo", "link"]
21
- # irb(main):008:0> node['class'] = 'green'
22
- # => "green"
23
- # irb(main):009:0> node
24
- # => <a href="#foo" id="link" class="green">link</a>
25
- # irb(main):010:0>
13
+ # node = Nokogiri::XML::DocumentFragment.parse("<a href='#foo' id='link'>link</a>").at_css("a")
14
+ # node.to_html # => "<a href=\"#foo\" id=\"link\">link</a>"
15
+ # node['href'] # => "#foo"
16
+ # node.keys # => ["href", "id"]
17
+ # node.values # => ["#foo", "link"]
18
+ # node['class'] = 'green' # => "green"
19
+ # node.to_html # => "<a href=\"#foo\" id=\"link\" class=\"green\">link</a>"
26
20
  #
27
- # See Nokogiri::XML::Node#[] and Nokogiri::XML#[]= for more information.
21
+ # See the method group entitled "Working With Node Attributes" for the full set of methods.
28
22
  #
29
- # Nokogiri::XML::Node also has methods that let you move around your
23
+ # {Nokogiri::XML::Node} also has methods that let you move around your
30
24
  # tree. For navigating your tree, see:
31
25
  #
32
- # * Nokogiri::XML::Node#parent
33
- # * Nokogiri::XML::Node#children
34
- # * Nokogiri::XML::Node#next
35
- # * Nokogiri::XML::Node#previous
36
- #
26
+ # * {#parent}
27
+ # * {#children}
28
+ # * {#next}
29
+ # * {#previous}
37
30
  #
38
31
  # When printing or otherwise emitting a document or a node (and
39
32
  # its subtree), there are a few methods you might want to use:
40
33
  #
41
- # * content, text, inner_text, to_str: emit plaintext
42
- #
43
- # These methods will all emit the plaintext version of your
44
- # document, meaning that entities will be replaced (e.g., "&lt;"
45
- # will be replaced with "<"), meaning that any sanitizing will
46
- # likely be un-done in the output.
34
+ # * {#content}, {#text}, {#inner_text}, {#to_str}: These methods will all <b>emit plaintext</b>,
35
+ # meaning that entities will be replaced (e.g., "&lt;" will be replaced with "<"), meaning
36
+ # that any sanitizing will likely be un-done in the output.
47
37
  #
48
- # * to_s, to_xml, to_html, inner_html: emit well-formed markup
38
+ # * {#to_s}, {#to_xml}, {#to_html}, {#inner_html}: These methods will all <b>emit
39
+ # properly-escaped markup</b>, meaning that it's suitable for consumption by browsers,
40
+ # parsers, etc.
49
41
  #
50
- # These methods will all emit properly-escaped markup, meaning
51
- # that it's suitable for consumption by browsers, parsers, etc.
42
+ # You may search this node's subtree using {#xpath} and {#css}
52
43
  #
53
- # You may search this node's subtree using Searchable#xpath and Searchable#css
54
44
  class Node
55
45
  include Nokogiri::XML::PP::Node
56
46
  include Nokogiri::XML::Searchable
57
47
  include Enumerable
58
48
 
59
- # Element node type, see Nokogiri::XML::Node#element?
49
+ # Element node type, see {Nokogiri::XML::Node#element?}
60
50
  ELEMENT_NODE = 1
61
51
  # Attribute node type
62
52
  ATTRIBUTE_NODE = 2
63
- # Text node type, see Nokogiri::XML::Node#text?
53
+ # Text node type, see {Nokogiri::XML::Node#text?}
64
54
  TEXT_NODE = 3
65
- # CDATA node type, see Nokogiri::XML::Node#cdata?
55
+ # CDATA node type, see {Nokogiri::XML::Node#cdata?}
66
56
  CDATA_SECTION_NODE = 4
67
57
  # Entity reference node type
68
58
  ENTITY_REF_NODE = 5
@@ -70,9 +60,9 @@ module Nokogiri
70
60
  ENTITY_NODE = 6
71
61
  # PI node type
72
62
  PI_NODE = 7
73
- # Comment node type, see Nokogiri::XML::Node#comment?
63
+ # Comment node type, see {Nokogiri::XML::Node#comment?}
74
64
  COMMENT_NODE = 8
75
- # Document node type, see Nokogiri::XML::Node#xml?
65
+ # Document node type, see {Nokogiri::XML::Node#xml?}
76
66
  DOCUMENT_NODE = 9
77
67
  # Document type node type
78
68
  DOCUMENT_TYPE_NODE = 10
@@ -80,7 +70,7 @@ module Nokogiri
80
70
  DOCUMENT_FRAG_NODE = 11
81
71
  # Notation node type
82
72
  NOTATION_NODE = 12
83
- # HTML document node type, see Nokogiri::XML::Node#html?
73
+ # HTML document node type, see {Nokogiri::XML::Node#html?}
84
74
  HTML_DOCUMENT_NODE = 13
85
75
  # DTD node type
86
76
  DTD_NODE = 14
@@ -99,8 +89,15 @@ module Nokogiri
99
89
  # DOCB document node type
100
90
  DOCB_DOCUMENT_NODE = 21
101
91
 
102
- def initialize(name, document) # :nodoc:
103
- # ... Ya. This is empty on purpose.
92
+ ##
93
+ # Create a new node with +name+ sharing GC lifecycle with +document+.
94
+ # @param name [String]
95
+ # @param document [Nokogiri::XML::Document]
96
+ # @yieldparam node [Nokogiri::XML::Node]
97
+ # @return [Nokogiri::XML::Node]
98
+ # @see Nokogiri::XML::Node.new
99
+ def initialize(name, document)
100
+ # This is intentionally empty.
104
101
  end
105
102
 
106
103
  ###
@@ -86,7 +86,8 @@ module Nokogiri
86
86
  private :initialize
87
87
 
88
88
  ###
89
- # Get a list of attributes for the current node.
89
+ # Get the attributes of the current node as a Hash
90
+ # @return [Hash<String, String>] Attribute names and values
90
91
  def attributes
91
92
  attrs_hash = attribute_nodes.each_with_object({}) do |node, hash|
92
93
  hash[node.name] = node.to_s
@@ -96,14 +97,6 @@ module Nokogiri
96
97
  attrs_hash
97
98
  end
98
99
 
99
- ###
100
- # Get a list of attributes for the current node
101
- def attribute_nodes
102
- nodes = attr_nodes
103
- nodes.each { |v| v.instance_variable_set(:@_r, self) }
104
- nodes
105
- end
106
-
107
100
  ###
108
101
  # Move the cursor through the document yielding the cursor to the block
109
102
  def each
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Nokogiri
3
3
  module XML
4
- class XPath
4
+ module XPath
5
5
  class SyntaxError < XML::SyntaxError
6
6
  def to_s
7
7
  [super.chomp, str1].compact.join(': ')
@@ -3,9 +3,7 @@ require 'nokogiri/xml/xpath/syntax_error'
3
3
 
4
4
  module Nokogiri
5
5
  module XML
6
- class XPath
7
- # The Nokogiri::XML::Document tied to this XPath instance
8
- attr_accessor :document
6
+ module XPath
9
7
  end
10
8
  end
11
9
  end
data/lib/nokogiri.rb CHANGED
@@ -8,12 +8,8 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
8
8
  require 'nokogiri/jruby/dependencies'
9
9
  end
10
10
 
11
- begin
12
- RUBY_VERSION =~ /(\d+\.\d+)/
13
- require "nokogiri/#{$1}/nokogiri"
14
- rescue LoadError
15
- require 'nokogiri/nokogiri'
16
- end
11
+ require 'nokogiri/extension'
12
+
17
13
  require 'nokogiri/version'
18
14
  require 'nokogiri/syntax_error'
19
15
  require 'nokogiri/xml'
@@ -0,0 +1,81 @@
1
+ This patch is a result of rake-compiler-dock using centos 7 (manylinux2014) to cross-compile.
2
+
3
+ Centos, for reasons I have not been able to discern, implements `isnan` and `isinf` as a function
4
+ and not as a macro. Debian knows how to resolve that function at dynamic-link time (despite using a
5
+ macro at compile time), but musl-based systems (like alpine) do not. Running `nm` on nokogiri.so
6
+ created on such a centos system shows:
7
+
8
+ ```
9
+ U __isinf@@GLIBC_2.2.5
10
+ U __isnan@@GLIBC_2.2.5
11
+ ```
12
+
13
+ (see https://github.com/sparklemotion/nokogiri/pull/2142 for more info)
14
+
15
+ This patch avoids using glibc's `isnan` and `isinf` calls, instead using libxml2's fallback
16
+ implementation. There's history here, see libxml2 commit 8813f39:
17
+
18
+ commit 8813f39
19
+ Author: Nick Wellnhofer <wellnhofer@aevum.de>
20
+ Date: 2017-09-21 00:11:26 +0200
21
+
22
+ Simplify XPath NaN, inf and -0 handling
23
+
24
+ Use C99 macros NAN, INFINITY, isnan, isinf. If they're not available:
25
+
26
+ - Assume that (0.0 / 0.0) generates a NaN and !(x == x) tests for NaN.
27
+ - Use C89's HUGE_VAL for INFINITY.
28
+
29
+ Remove manual handling of NaN, infinity and negative zero in functions
30
+ xmlXPathValueFlipSign and xmlXPathDivValues.
31
+
32
+ Remove xmlXPathGetSign. All the tests for negative zero can be replaced
33
+ with a test for negative or positive zero.
34
+
35
+ Simplify xmlXPathRoundFunction.
36
+
37
+ Remove Trio dependency.
38
+
39
+ This should work on IEEE 754 compliant implementations even if the C99
40
+ macros aren't available, but will likely break some ancient platforms.
41
+ If problems arise, my plan is to port the relevant trionan.c solution
42
+ to xpath.c. Note that non-compliant implementations are impossible
43
+ to fully support, anyway, since XPath requires IEEE 754.
44
+
45
+ This patch would be unnecessary if any of the following was true:
46
+
47
+ * centos implements these as macros, and doesn't generate an unresolved symbol for either in the shared library
48
+ * we had a way to ensure `__isinf` and `__isnan` resolve on musl (e.g., we implement them locally)
49
+
50
+ diff --git a/xpath.c b/xpath.c
51
+ index 9f64ab9..5b6d999 100644
52
+ --- a/xpath.c
53
+ +++ b/xpath.c
54
+ @@ -509,11 +509,7 @@ xmlXPathInit(void) {
55
+ */
56
+ int
57
+ xmlXPathIsNaN(double val) {
58
+ -#ifdef isnan
59
+ - return isnan(val);
60
+ -#else
61
+ return !(val == val);
62
+ -#endif
63
+ }
64
+
65
+ /**
66
+ @@ -524,15 +520,11 @@ xmlXPathIsNaN(double val) {
67
+ */
68
+ int
69
+ xmlXPathIsInf(double val) {
70
+ -#ifdef isinf
71
+ - return isinf(val) ? (val > 0 ? 1 : -1) : 0;
72
+ -#else
73
+ if (val >= INFINITY)
74
+ return 1;
75
+ if (val <= -INFINITY)
76
+ return -1;
77
+ return 0;
78
+ -#endif
79
+ }
80
+
81
+ #endif /* SCHEMAS or XPATH */
@@ -0,0 +1,70 @@
1
+ From ca565c1edef9a455453fa8564270cc9c5813e1b9 Mon Sep 17 00:00:00 2001
2
+ From: Mike Dalessio <mike.dalessio@gmail.com>
3
+ Date: Sun, 31 Jan 2021 09:53:56 -0500
4
+ Subject: [PATCH] parser.c: shrink the input buffer when appropriate
5
+
6
+ Fixes GNOME/libxml2#200
7
+
8
+ Also see discussions at:
9
+ - GNOME/libxml2#192
10
+ - https://gitlab.gnome.org/nwellnhof/libxml2/-/commit/99bda1e
11
+ - https://github.com/sparklemotion/nokogiri/issues/2132
12
+ ---
13
+ parser.c | 6 ++++++
14
+ 1 file changed, 6 insertions(+)
15
+
16
+ diff --git a/parser.c b/parser.c
17
+ index a7bdc7f..efde672 100644
18
+ --- a/parser.c
19
+ +++ b/parser.c
20
+ @@ -4204,6 +4204,7 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) {
21
+ }
22
+ count++;
23
+ if (count > 50) {
24
+ + SHRINK;
25
+ GROW;
26
+ count = 0;
27
+ if (ctxt->instate == XML_PARSER_EOF) {
28
+ @@ -4291,6 +4292,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) {
29
+ buf[len++] = cur;
30
+ count++;
31
+ if (count > 50) {
32
+ + SHRINK;
33
+ GROW;
34
+ count = 0;
35
+ if (ctxt->instate == XML_PARSER_EOF) {
36
+ @@ -4571,6 +4573,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) {
37
+ }
38
+ count++;
39
+ if (count > 50) {
40
+ + SHRINK;
41
+ GROW;
42
+ count = 0;
43
+ if (ctxt->instate == XML_PARSER_EOF)
44
+ @@ -4776,6 +4779,7 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf,
45
+
46
+ count++;
47
+ if (count > 50) {
48
+ + SHRINK;
49
+ GROW;
50
+ count = 0;
51
+ if (ctxt->instate == XML_PARSER_EOF) {
52
+ @@ -5186,6 +5190,7 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
53
+ }
54
+ count++;
55
+ if (count > 50) {
56
+ + SHRINK;
57
+ GROW;
58
+ if (ctxt->instate == XML_PARSER_EOF) {
59
+ xmlFree(buf);
60
+ @@ -9783,6 +9788,7 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) {
61
+ sl = l;
62
+ count++;
63
+ if (count > 50) {
64
+ + SHRINK;
65
+ GROW;
66
+ if (ctxt->instate == XML_PARSER_EOF) {
67
+ xmlFree(buf);
68
+ --
69
+ 2.25.1
70
+