nokogiri 1.10.9 → 1.11.0.rc4

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +1015 -947
  3. data/README.md +24 -22
  4. data/ext/nokogiri/depend +476 -357
  5. data/ext/nokogiri/extconf.rb +485 -352
  6. data/ext/nokogiri/html_document.c +79 -78
  7. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  8. data/ext/nokogiri/nokogiri.c +34 -40
  9. data/ext/nokogiri/nokogiri.h +26 -17
  10. data/ext/nokogiri/xml_document.c +18 -4
  11. data/ext/nokogiri/xml_io.c +8 -6
  12. data/ext/nokogiri/xml_node.c +21 -1
  13. data/ext/nokogiri/xml_node_set.c +1 -1
  14. data/ext/nokogiri/xml_reader.c +6 -17
  15. data/ext/nokogiri/xml_relax_ng.c +29 -11
  16. data/ext/nokogiri/xml_sax_parser.c +2 -7
  17. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  18. data/ext/nokogiri/xml_schema.c +55 -13
  19. data/ext/nokogiri/xml_xpath_context.c +80 -4
  20. data/ext/nokogiri/xslt_stylesheet.c +1 -8
  21. data/lib/nokogiri.rb +4 -21
  22. data/lib/nokogiri/css.rb +1 -0
  23. data/lib/nokogiri/css/node.rb +1 -0
  24. data/lib/nokogiri/css/parser.rb +63 -62
  25. data/lib/nokogiri/css/parser.y +2 -2
  26. data/lib/nokogiri/css/parser_extras.rb +39 -36
  27. data/lib/nokogiri/css/syntax_error.rb +1 -0
  28. data/lib/nokogiri/css/tokenizer.rb +1 -0
  29. data/lib/nokogiri/css/xpath_visitor.rb +73 -43
  30. data/lib/nokogiri/decorators/slop.rb +1 -0
  31. data/lib/nokogiri/html.rb +1 -0
  32. data/lib/nokogiri/html/builder.rb +1 -0
  33. data/lib/nokogiri/html/document.rb +13 -26
  34. data/lib/nokogiri/html/document_fragment.rb +1 -0
  35. data/lib/nokogiri/html/element_description.rb +1 -0
  36. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  37. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  38. data/lib/nokogiri/html/sax/parser.rb +1 -0
  39. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  40. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  41. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  42. data/lib/nokogiri/syntax_error.rb +1 -0
  43. data/lib/nokogiri/version.rb +3 -109
  44. data/lib/nokogiri/version/constant.rb +5 -0
  45. data/lib/nokogiri/version/info.rb +182 -0
  46. data/lib/nokogiri/xml.rb +1 -0
  47. data/lib/nokogiri/xml/attr.rb +1 -0
  48. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  49. data/lib/nokogiri/xml/builder.rb +3 -2
  50. data/lib/nokogiri/xml/cdata.rb +1 -0
  51. data/lib/nokogiri/xml/character_data.rb +1 -0
  52. data/lib/nokogiri/xml/document.rb +20 -15
  53. data/lib/nokogiri/xml/document_fragment.rb +5 -6
  54. data/lib/nokogiri/xml/dtd.rb +1 -0
  55. data/lib/nokogiri/xml/element_content.rb +1 -0
  56. data/lib/nokogiri/xml/element_decl.rb +1 -0
  57. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  58. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  59. data/lib/nokogiri/xml/namespace.rb +1 -0
  60. data/lib/nokogiri/xml/node.rb +587 -249
  61. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  62. data/lib/nokogiri/xml/node_set.rb +1 -0
  63. data/lib/nokogiri/xml/notation.rb +1 -0
  64. data/lib/nokogiri/xml/parse_options.rb +10 -3
  65. data/lib/nokogiri/xml/pp.rb +1 -0
  66. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  67. data/lib/nokogiri/xml/pp/node.rb +1 -0
  68. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  69. data/lib/nokogiri/xml/reader.rb +7 -3
  70. data/lib/nokogiri/xml/relax_ng.rb +7 -2
  71. data/lib/nokogiri/xml/sax.rb +1 -0
  72. data/lib/nokogiri/xml/sax/document.rb +1 -0
  73. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  74. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  75. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  76. data/lib/nokogiri/xml/schema.rb +13 -4
  77. data/lib/nokogiri/xml/searchable.rb +25 -16
  78. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  79. data/lib/nokogiri/xml/text.rb +1 -0
  80. data/lib/nokogiri/xml/xpath.rb +1 -0
  81. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  82. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  83. data/lib/nokogiri/xslt.rb +1 -0
  84. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  85. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  86. data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +73 -0
  87. data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +103 -0
  88. data/patches/libxml2/0008-use-glibc-strlen.patch +53 -0
  89. metadata +81 -48
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class Node
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  ####
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class Notation < Struct.new(:name, :public_id, :system_id)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  ###
@@ -5,11 +6,11 @@ module Nokogiri
5
6
  #
6
7
  # == Building combinations of parse options
7
8
  # You can build your own combinations of these parse options by using any of the following methods:
8
- # *Note*: All examples attempt to set the +RECOVER+ & +NOENT+ options. All examples use Ruby 2 optional parameter syntax.
9
+ # *Note*: All examples attempt to set the +RECOVER+ & +NOENT+ options.
9
10
  # [Ruby's bitwise operators] You can use the Ruby bitwise operators to set various combinations.
10
- # Nokogiri.XML('<content>Chapter 1</content', options: Nokogiri::XML::ParseOptions.new((1 << 0) | (1 << 1)))
11
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new((1 << 0) | (1 << 1)))
11
12
  # [Method chaining] Every option has an equivalent method in lowercase. You can chain these methods together to set various combinations.
12
- # Nokogiri.XML('<content>Chapter 1</content', options: Nokogiri::XML::ParseOptions.new.recover.noent)
13
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new.recover.noent)
13
14
  # [Using Ruby Blocks] You can also setup parse combinations in the block passed to Nokogiri.XML or Nokogiri.HTML
14
15
  # Nokogiri.XML('<content>Chapter 1</content') {|config| config.recover.noent}
15
16
  #
@@ -72,6 +73,8 @@ module Nokogiri
72
73
  DEFAULT_XML = RECOVER | NONET
73
74
  # the default options used for parsing HTML documents
74
75
  DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET
76
+ # the default options used for parsing XML schemas
77
+ DEFAULT_SCHEMA = NONET
75
78
 
76
79
  attr_accessor :options
77
80
  def initialize options = STRICT
@@ -106,6 +109,10 @@ module Nokogiri
106
109
  @options & RECOVER == STRICT
107
110
  end
108
111
 
112
+ def ==(other)
113
+ other.to_i == to_i
114
+ end
115
+
109
116
  alias :to_i :options
110
117
 
111
118
  def inspect
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri/xml/pp/node'
2
3
  require 'nokogiri/xml/pp/character_data'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  module PP
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  module PP
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class ProcessingInstruction < Node
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  ###
@@ -87,9 +88,12 @@ module Nokogiri
87
88
  ###
88
89
  # Get a list of attributes for the current node.
89
90
  def attributes
90
- Hash[attribute_nodes.map { |node|
91
- [node.name, node.to_s]
92
- }].merge(namespaces || {})
91
+ attrs_hash = attribute_nodes.each_with_object({}) do |node, hash|
92
+ hash[node.name] = node.to_s
93
+ end
94
+ ns = namespaces
95
+ attrs_hash.merge!(ns) if ns
96
+ attrs_hash
93
97
  end
94
98
 
95
99
  ###
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class << self
4
5
  ###
5
6
  # Create a new Nokogiri::XML::RelaxNG document from +string_or_io+.
6
7
  # See Nokogiri::XML::RelaxNG for an example.
7
- def RelaxNG string_or_io
8
- RelaxNG.new(string_or_io)
8
+ def RelaxNG(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
9
+ RelaxNG.new(string_or_io, options)
9
10
  end
10
11
  end
11
12
 
@@ -26,6 +27,10 @@ module Nokogiri
26
27
  # end
27
28
  #
28
29
  # The list of errors are Nokogiri::XML::SyntaxError objects.
30
+ #
31
+ # NOTE: RelaxNG input is always treated as TRUSTED documents, meaning that they will cause the
32
+ # underlying parsing libraries to access network resources. This is counter to Nokogiri's
33
+ # "untrusted by default" security policy, but is a limitation of the underlying libraries.
29
34
  class RelaxNG < Nokogiri::XML::Schema
30
35
  end
31
36
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri/xml/sax/document'
2
3
  require 'nokogiri/xml/sax/parser_context'
3
4
  require 'nokogiri/xml/sax/parser'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  ###
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  module SAX
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  module SAX
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  module SAX
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class << self
4
5
  ###
5
6
  # Create a new Nokogiri::XML::Schema object using a +string_or_io+
6
7
  # object.
7
- def Schema string_or_io
8
- Schema.new(string_or_io)
8
+ def Schema(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
9
+ Schema.new(string_or_io, options)
9
10
  end
10
11
  end
11
12
 
@@ -26,15 +27,23 @@ module Nokogiri
26
27
  # end
27
28
  #
28
29
  # The list of errors are Nokogiri::XML::SyntaxError objects.
30
+ #
31
+ # NOTE: As of v1.11.0, Schema treats inputs as UNTRUSTED by default, and so external entities
32
+ # are not resolved from the network (`http://` or `ftp://`). Previously, parsing treated
33
+ # documents as "trusted" by default which was counter to Nokogiri's "untrusted by default"
34
+ # security policy. If a document is trusted, then the caller may turn off the NONET option via
35
+ # the ParseOptions to re-enable external entity resolution over a network connection.
29
36
  class Schema
30
37
  # Errors while parsing the schema file
31
38
  attr_accessor :errors
39
+ # The Nokogiri::XML::ParseOptions used to parse the schema
40
+ attr_accessor :parse_options
32
41
 
33
42
  ###
34
43
  # Create a new Nokogiri::XML::Schema object using a +string_or_io+
35
44
  # object.
36
- def self.new string_or_io
37
- from_document Nokogiri::XML(string_or_io)
45
+ def self.new string_or_io, options = ParseOptions::DEFAULT_SCHEMA
46
+ from_document(Nokogiri::XML(string_or_io), options)
38
47
  end
39
48
 
40
49
  ###
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  #
@@ -11,7 +12,9 @@ module Nokogiri
11
12
  # Regular expression used by Searchable#search to determine if a query
12
13
  # string is CSS or XPath
13
14
  LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/
14
-
15
+
16
+ # @!group Searching via XPath or CSS Queries
17
+
15
18
  ###
16
19
  # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
17
20
  #
@@ -45,7 +48,7 @@ module Nokogiri
45
48
  # )
46
49
  #
47
50
  # See Searchable#xpath and Searchable#css for further usage help.
48
- def search *args
51
+ def search(*args)
49
52
  paths, handler, ns, binds = extract_params(args)
50
53
 
51
54
  xpaths = paths.map(&:to_s).map do |path|
@@ -54,6 +57,7 @@ module Nokogiri
54
57
 
55
58
  xpath(*(xpaths + [ns, handler, binds].compact))
56
59
  end
60
+
57
61
  alias :/ :search
58
62
 
59
63
  ###
@@ -63,9 +67,10 @@ module Nokogiri
63
67
  # result. +paths+ must be one or more XPath or CSS queries.
64
68
  #
65
69
  # See Searchable#search for more information.
66
- def at *args
70
+ def at(*args)
67
71
  search(*args).first
68
72
  end
73
+
69
74
  alias :% :at
70
75
 
71
76
  ###
@@ -101,7 +106,7 @@ module Nokogiri
101
106
  # found in an XML document, where tags names are case-sensitive
102
107
  # (e.g., "H1" is distinct from "h1").
103
108
  #
104
- def css *args
109
+ def css(*args)
105
110
  rules, handler, ns, _ = extract_params(args)
106
111
 
107
112
  css_internal self, rules, handler, ns
@@ -114,7 +119,7 @@ module Nokogiri
114
119
  # match. +rules+ must be one or more CSS selectors.
115
120
  #
116
121
  # See Searchable#css for more information.
117
- def at_css *args
122
+ def at_css(*args)
118
123
  css(*args).first
119
124
  end
120
125
 
@@ -148,7 +153,7 @@ module Nokogiri
148
153
  # end
149
154
  # }.new)
150
155
  #
151
- def xpath *args
156
+ def xpath(*args)
152
157
  paths, handler, ns, binds = extract_params(args)
153
158
 
154
159
  xpath_internal self, paths, handler, ns, binds
@@ -161,17 +166,19 @@ module Nokogiri
161
166
  # match. +paths+ must be one or more XPath queries.
162
167
  #
163
168
  # See Searchable#xpath for more information.
164
- def at_xpath *args
169
+ def at_xpath(*args)
165
170
  xpath(*args).first
166
171
  end
167
172
 
173
+ # @!endgroup
174
+
168
175
  private
169
176
 
170
- def css_internal node, rules, handler, ns
177
+ def css_internal(node, rules, handler, ns)
171
178
  xpath_internal node, css_rules_to_xpath(rules, ns), handler, ns, nil
172
179
  end
173
180
 
174
- def xpath_internal node, paths, handler, ns, binds
181
+ def xpath_internal(node, paths, handler, ns, binds)
175
182
  document = node.document
176
183
  return NodeSet.new(document) unless document
177
184
 
@@ -186,12 +193,12 @@ module Nokogiri
186
193
  end
187
194
  end
188
195
 
189
- def xpath_impl node, path, handler, ns, binds
196
+ def xpath_impl(node, path, handler, ns, binds)
190
197
  ctx = XPathContext.new(node)
191
198
  ctx.register_namespaces(ns)
192
- path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
199
+ path = path.gsub(/xmlns:/, " :") unless Nokogiri.uses_libxml?
193
200
 
194
- binds.each do |key,value|
201
+ binds.each do |key, value|
195
202
  ctx.register_variable key.to_s, value
196
203
  end if binds
197
204
 
@@ -202,13 +209,15 @@ module Nokogiri
202
209
  rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
203
210
  end
204
211
 
205
- def xpath_query_from_css_rule rule, ns
212
+ def xpath_query_from_css_rule(rule, ns)
213
+ visitor = Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new
206
214
  self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
207
- CSS.xpath_for(rule.to_s, :prefix => implied_xpath_context, :ns => ns)
208
- end.join(' | ')
215
+ CSS.xpath_for(rule.to_s, {:prefix => implied_xpath_context, :ns => ns,
216
+ :visitor => visitor})
217
+ end.join(" | ")
209
218
  end
210
219
 
211
- def extract_params params # :nodoc:
220
+ def extract_params(params) # :nodoc:
212
221
  handler = params.find do |param|
213
222
  ![Hash, String, Symbol].include?(param.class)
214
223
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  ###
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class Text < Nokogiri::XML::CharacterData
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri/xml/xpath/syntax_error'
2
3
 
3
4
  module Nokogiri
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class XPath
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XML
3
4
  class XPathContext
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri/xslt/stylesheet'
2
3
 
3
4
  module Nokogiri
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Nokogiri
2
3
  module XSLT
3
4
  ###
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'nokogiri'
2
3
 
3
4
  module XSD # :nodoc:
@@ -0,0 +1,73 @@
1
+ From 4f51a6d2b1755ce5b36c524c215aad70d864ac1d Mon Sep 17 00:00:00 2001
2
+ From: Mike Dalessio <mike.dalessio@gmail.com>
3
+ Date: Mon, 3 Aug 2020 17:36:05 -0400
4
+ Subject: [PATCH 1/2] htmlParseComment: treat `--!>` as if it closed the
5
+ comment
6
+
7
+ See guidance provided on incorrectly-closed comments here:
8
+
9
+ https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment
10
+ ---
11
+ HTMLparser.c | 28 ++++++++++++++++++++--------
12
+ 1 file changed, 20 insertions(+), 8 deletions(-)
13
+
14
+ diff --git a/HTMLparser.c b/HTMLparser.c
15
+ index 7b6d689..4d43479 100644
16
+ --- a/HTMLparser.c
17
+ +++ b/HTMLparser.c
18
+ @@ -3300,6 +3300,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
19
+ int q, ql;
20
+ int r, rl;
21
+ int cur, l;
22
+ + int next, nl;
23
+ xmlParserInputState state;
24
+
25
+ /*
26
+ @@ -3332,6 +3333,21 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
27
+ while (IS_CHAR(cur) &&
28
+ ((cur != '>') ||
29
+ (r != '-') || (q != '-'))) {
30
+ + NEXTL(l);
31
+ + next = CUR_CHAR(nl);
32
+ + if (next == 0) {
33
+ + SHRINK;
34
+ + GROW;
35
+ + next = CUR_CHAR(nl);
36
+ + }
37
+ +
38
+ + if ((q == '-') && (r == '-') && (cur == '!') && (next == '>')) {
39
+ + htmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
40
+ + "Comment incorrectly closed by '--!>'", NULL, NULL);
41
+ + cur = '>';
42
+ + break;
43
+ + }
44
+ +
45
+ if (len + 5 >= size) {
46
+ xmlChar *tmp;
47
+
48
+ @@ -3345,18 +3361,14 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
49
+ }
50
+ buf = tmp;
51
+ }
52
+ - COPY_BUF(ql,buf,len,q);
53
+ + COPY_BUF(ql,buf,len,q);
54
+ +
55
+ q = r;
56
+ ql = rl;
57
+ r = cur;
58
+ rl = l;
59
+ - NEXTL(l);
60
+ - cur = CUR_CHAR(l);
61
+ - if (cur == 0) {
62
+ - SHRINK;
63
+ - GROW;
64
+ - cur = CUR_CHAR(l);
65
+ - }
66
+ + cur = next;
67
+ + l = nl;
68
+ }
69
+ buf[len] = 0;
70
+ if (IS_CHAR(cur)) {
71
+ --
72
+ 2.25.1
73
+
@@ -0,0 +1,103 @@
1
+ From b20d746fa7cbb74716171bc49d836af99927e41e Mon Sep 17 00:00:00 2001
2
+ From: Mike Dalessio <mike.dalessio@gmail.com>
3
+ Date: Sun, 11 Oct 2020 14:15:37 -0400
4
+ Subject: [PATCH 2/2] use new htmlParseLookupCommentEnd to find comment ends
5
+
6
+ Note that the caret in error messages generated during comment parsing
7
+ may have moved by one byte.
8
+
9
+ See guidance provided on incorrectly-closed comments here:
10
+
11
+ https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment
12
+ ---
13
+ HTMLparser.c | 46 +++++++++++++++++++++++++++++++++++++---------
14
+ 1 file changed, 37 insertions(+), 9 deletions(-)
15
+
16
+ diff --git a/HTMLparser.c b/HTMLparser.c
17
+ index 4d43479..000dc3d 100644
18
+ --- a/HTMLparser.c
19
+ +++ b/HTMLparser.c
20
+ @@ -5331,6 +5331,39 @@ htmlParseLookupChars(htmlParserCtxtPtr ctxt, const xmlChar * stop,
21
+ return (-1);
22
+ }
23
+
24
+ +/**
25
+ + * htmlParseLookupCommentEnd:
26
+ + * @ctxt: an HTML parser context
27
+ + *
28
+ + * Try to find a comment end tag in the input stream
29
+ + * The search includes "-->" as well as WHATWG-recommended incorrectly-closed tags.
30
+ + * (See https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment)
31
+ + * This function has a side effect of (possibly) incrementing ctxt->checkIndex
32
+ + * to avoid rescanning sequences of bytes, it DOES change the state of the
33
+ + * parser, do not use liberally.
34
+ + * This wraps to htmlParseLookupSequence()
35
+ + *
36
+ + * Returns the index to the current parsing point if the full sequence is available, -1 otherwise.
37
+ + */
38
+ +static int
39
+ +htmlParseLookupCommentEnd(htmlParserCtxtPtr ctxt)
40
+ +{
41
+ + int mark = 0;
42
+ + int cur = CUR_PTR - BASE_PTR;
43
+ +
44
+ + while (mark >= 0) {
45
+ + mark = htmlParseLookupSequence(ctxt, '-', '-', 0, 1, 1);
46
+ + if ((mark < 0) ||
47
+ + (NXT(mark+2) == '>') ||
48
+ + ((NXT(mark+2) == '!') && (NXT(mark+3) == '>'))) {
49
+ + return mark;
50
+ + }
51
+ + ctxt->checkIndex = cur + mark + 1;
52
+ + }
53
+ + return mark;
54
+ +}
55
+ +
56
+ +
57
+ /**
58
+ * htmlParseTryOrFinish:
59
+ * @ctxt: an HTML parser context
60
+ @@ -5507,8 +5540,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
61
+ cur = in->cur[0];
62
+ if ((cur == '<') && (next == '!') &&
63
+ (in->cur[2] == '-') && (in->cur[3] == '-')) {
64
+ - if ((!terminate) &&
65
+ - (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
66
+ + if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0))
67
+ goto done;
68
+ #ifdef DEBUG_PUSH
69
+ xmlGenericError(xmlGenericErrorContext,
70
+ @@ -5567,8 +5599,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
71
+ next = in->cur[1];
72
+ if ((cur == '<') && (next == '!') &&
73
+ (in->cur[2] == '-') && (in->cur[3] == '-')) {
74
+ - if ((!terminate) &&
75
+ - (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
76
+ + if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0))
77
+ goto done;
78
+ #ifdef DEBUG_PUSH
79
+ xmlGenericError(xmlGenericErrorContext,
80
+ @@ -5614,8 +5645,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
81
+ next = in->cur[1];
82
+ if ((cur == '<') && (next == '!') &&
83
+ (in->cur[2] == '-') && (in->cur[3] == '-')) {
84
+ - if ((!terminate) &&
85
+ - (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
86
+ + if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0))
87
+ goto done;
88
+ #ifdef DEBUG_PUSH
89
+ xmlGenericError(xmlGenericErrorContext,
90
+ @@ -5871,9 +5901,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
91
+ htmlParseDocTypeDecl(ctxt);
92
+ } else if ((cur == '<') && (next == '!') &&
93
+ (in->cur[2] == '-') && (in->cur[3] == '-')) {
94
+ - if ((!terminate) &&
95
+ - (htmlParseLookupSequence(
96
+ - ctxt, '-', '-', '>', 1, 1) < 0))
97
+ + if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0))
98
+ goto done;
99
+ #ifdef DEBUG_PUSH
100
+ xmlGenericError(xmlGenericErrorContext,
101
+ --
102
+ 2.25.1
103
+