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
  module Nokogiri
3
4
  module XML
4
5
  ####
@@ -12,10 +13,10 @@ module Nokogiri
12
13
  # The Document this NodeSet is associated with
13
14
  attr_accessor :document
14
15
 
15
- alias :clone :dup
16
+ alias_method :clone, :dup
16
17
 
17
18
  # Create a NodeSet with +document+ defaulting to +list+
18
- def initialize document, list = []
19
+ def initialize(document, list = [])
19
20
  @document = document
20
21
  document.decorate(self)
21
22
  list.each { |x| self << x }
@@ -24,8 +25,9 @@ module Nokogiri
24
25
 
25
26
  ###
26
27
  # Get the first element of the NodeSet.
27
- def first n = nil
28
+ def first(n = nil)
28
29
  return self[0] unless n
30
+
29
31
  list = []
30
32
  [n, length].min.times { |i| list << self[i] }
31
33
  list
@@ -47,7 +49,7 @@ module Nokogiri
47
49
  # Returns the index of the first node in self that is == to +node+ or meets the given block. Returns nil if no match is found.
48
50
  def index(node = nil)
49
51
  if node
50
- warn "given block not used" if block_given?
52
+ warn("given block not used") if block_given?
51
53
  each_with_index { |member, j| return j if member == node }
52
54
  elsif block_given?
53
55
  each_with_index { |member, j| return j if yield(member) }
@@ -57,18 +59,18 @@ module Nokogiri
57
59
 
58
60
  ###
59
61
  # Insert +datum+ before the first Node in this NodeSet
60
- def before datum
61
- first.before datum
62
+ def before(datum)
63
+ first.before(datum)
62
64
  end
63
65
 
64
66
  ###
65
67
  # Insert +datum+ after the last Node in this NodeSet
66
- def after datum
67
- last.after datum
68
+ def after(datum)
69
+ last.after(datum)
68
70
  end
69
71
 
70
- alias :<< :push
71
- alias :remove :unlink
72
+ alias_method :<<, :push
73
+ alias_method :remove, :unlink
72
74
 
73
75
  ###
74
76
  # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
@@ -77,7 +79,7 @@ module Nokogiri
77
79
  # selectors. For example:
78
80
  #
79
81
  # For more information see Nokogiri::XML::Searchable#css
80
- def css *args
82
+ def css(*args)
81
83
  rules, handler, ns, _ = extract_params(args)
82
84
  paths = css_rules_to_xpath(rules, ns)
83
85
 
@@ -93,7 +95,7 @@ module Nokogiri
93
95
  # queries.
94
96
  #
95
97
  # For more information see Nokogiri::XML::Searchable#xpath
96
- def xpath *args
98
+ def xpath(*args)
97
99
  paths, handler, ns, binds = extract_params(args)
98
100
 
99
101
  inject(NodeSet.new(document)) do |set, node|
@@ -101,13 +103,6 @@ module Nokogiri
101
103
  end
102
104
  end
103
105
 
104
- ###
105
- # Search this NodeSet's nodes' immediate children using CSS selector +selector+
106
- def > selector
107
- ns = document.root.namespaces
108
- xpath CSS.xpath_for(selector, :prefix => "./", :ns => ns).first
109
- end
110
-
111
106
  ###
112
107
  # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
113
108
  #
@@ -120,18 +115,18 @@ module Nokogiri
120
115
  #
121
116
  # node_set.at(3) # same as node_set[3]
122
117
  #
123
- def at *args
118
+ def at(*args)
124
119
  if args.length == 1 && args.first.is_a?(Numeric)
125
120
  return self[args.first]
126
121
  end
127
122
 
128
123
  super(*args)
129
124
  end
130
- alias :% :at
125
+ alias_method :%, :at
131
126
 
132
127
  ###
133
128
  # Filter this list for nodes that match +expr+
134
- def filter expr
129
+ def filter(expr)
135
130
  find_all { |node| node.matches?(expr) }
136
131
  end
137
132
 
@@ -140,7 +135,7 @@ module Nokogiri
140
135
  # NodeSet.
141
136
  #
142
137
  # See Nokogiri::XML::Node#add_class for more information.
143
- def add_class name
138
+ def add_class(name)
144
139
  each do |el|
145
140
  el.add_class(name)
146
141
  end
@@ -152,7 +147,7 @@ module Nokogiri
152
147
  # NodeSet.
153
148
  #
154
149
  # See Nokogiri::XML::Node#append_class for more information.
155
- def append_class name
150
+ def append_class(name)
156
151
  each do |el|
157
152
  el.append_class(name)
158
153
  end
@@ -164,7 +159,7 @@ module Nokogiri
164
159
  # NodeSet.
165
160
  #
166
161
  # See Nokogiri::XML::Node#remove_class for more information.
167
- def remove_class name = nil
162
+ def remove_class(name = nil)
168
163
  each do |el|
169
164
  el.remove_class(name)
170
165
  end
@@ -204,31 +199,31 @@ module Nokogiri
204
199
  #
205
200
  # node_set.attr("class") { |node| node.name }
206
201
  #
207
- def attr key, value = nil, &block
202
+ def attr(key, value = nil, &block)
208
203
  unless key.is_a?(Hash) || (key && (value || block))
209
204
  return first ? first.attribute(key) : nil
210
205
  end
211
206
 
212
207
  hash = key.is_a?(Hash) ? key : { key => value }
213
208
 
214
- hash.each do |k,v|
209
+ hash.each do |k, v|
215
210
  each do |node|
216
- node[k] = v || block.call(node)
211
+ node[k] = v || yield(node)
217
212
  end
218
213
  end
219
214
 
220
215
  self
221
216
  end
222
- alias :set :attr
223
- alias :attribute :attr
217
+ alias_method :set, :attr
218
+ alias_method :attribute, :attr
224
219
 
225
220
  ###
226
221
  # Remove the attributed named +name+ from all Node objects in the NodeSet
227
- def remove_attr name
228
- each { |el| el.delete name }
222
+ def remove_attr(name)
223
+ each { |el| el.delete(name) }
229
224
  self
230
225
  end
231
- alias remove_attribute remove_attr
226
+ alias_method :remove_attribute, :remove_attr
232
227
 
233
228
  ###
234
229
  # Iterate over each node, yielding to +block+
@@ -255,20 +250,20 @@ module Nokogiri
255
250
  #
256
251
  # See Nokogiri::XML::Node#content for more information.
257
252
  def inner_text
258
- collect(&:inner_text).join('')
253
+ collect(&:inner_text).join("")
259
254
  end
260
- alias :text :inner_text
255
+ alias_method :text, :inner_text
261
256
 
262
257
  ###
263
258
  # Get the inner html of all contained Node objects
264
- def inner_html *args
265
- collect{|j| j.inner_html(*args) }.join('')
259
+ def inner_html(*args)
260
+ collect { |j| j.inner_html(*args) }.join("")
266
261
  end
267
262
 
268
263
  ###
269
264
  # Wrap this NodeSet with +html+
270
- def wrap html
271
- map { |node| node.wrap html }
265
+ def wrap(html)
266
+ map { |node| node.wrap(html) }
272
267
  end
273
268
 
274
269
  ###
@@ -279,10 +274,10 @@ module Nokogiri
279
274
 
280
275
  ###
281
276
  # Convert this NodeSet to HTML
282
- def to_html *args
277
+ def to_html(*args)
283
278
  if Nokogiri.jruby?
284
279
  options = args.first.is_a?(Hash) ? args.shift : {}
285
- if !options[:save_with]
280
+ unless options[:save_with]
286
281
  options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
287
282
  end
288
283
  args.insert(0, options)
@@ -292,25 +287,26 @@ module Nokogiri
292
287
 
293
288
  ###
294
289
  # Convert this NodeSet to XHTML
295
- def to_xhtml *args
290
+ def to_xhtml(*args)
296
291
  map { |x| x.to_xhtml(*args) }.join
297
292
  end
298
293
 
299
294
  ###
300
295
  # Convert this NodeSet to XML
301
- def to_xml *args
296
+ def to_xml(*args)
302
297
  map { |x| x.to_xml(*args) }.join
303
298
  end
304
299
 
305
- alias :size :length
306
- alias :to_ary :to_a
300
+ alias_method :size, :length
301
+ alias_method :to_ary, :to_a
307
302
 
308
303
  ###
309
304
  # Removes the last element from set and returns it, or +nil+ if
310
305
  # the set is empty
311
306
  def pop
312
307
  return nil if length == 0
313
- delete last
308
+
309
+ delete(last)
314
310
  end
315
311
 
316
312
  ###
@@ -318,16 +314,18 @@ module Nokogiri
318
314
  # +nil+ if the set is empty.
319
315
  def shift
320
316
  return nil if length == 0
321
- delete first
317
+
318
+ delete(first)
322
319
  end
323
320
 
324
321
  ###
325
322
  # Equality -- Two NodeSets are equal if the contain the same number
326
323
  # of elements and if each element is equal to the corresponding
327
324
  # element in the other NodeSet
328
- def == other
325
+ def ==(other)
329
326
  return false unless other.is_a?(Nokogiri::XML::NodeSet)
330
327
  return false unless length == other.length
328
+
331
329
  each_with_index do |node, i|
332
330
  return false unless node == other[i]
333
331
  end
@@ -351,7 +349,7 @@ module Nokogiri
351
349
  def reverse
352
350
  node_set = NodeSet.new(document)
353
351
  (length - 1).downto(0) do |x|
354
- node_set.push self[x]
352
+ node_set.push(self[x])
355
353
  end
356
354
  node_set
357
355
  end
@@ -359,14 +357,12 @@ module Nokogiri
359
357
  ###
360
358
  # Return a nicely formated string representation
361
359
  def inspect
362
- "[#{map(&:inspect).join ', '}]"
360
+ "[#{map(&:inspect).join(", ")}]"
363
361
  end
364
362
 
365
- alias :+ :|
366
-
367
- # @private
368
- IMPLIED_XPATH_CONTEXTS = [ './/'.freeze, 'self::'.freeze ].freeze # :nodoc:
363
+ alias_method :+, :|
369
364
 
365
+ IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
370
366
  end
371
367
  end
372
368
  end
@@ -1,7 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
5
+ # Struct representing an {XML Schema Notation}[https://www.w3.org/TR/xml/#Notations]
4
6
  class Notation < Struct.new(:name, :public_id, :system_id)
7
+ # dead comment to ensure rdoc processing
8
+
9
+ # :attr: name (String)
10
+ # The name for the element.
11
+
12
+ # :attr: public_id (String)
13
+ # The URI corresponding to the public identifier
14
+
15
+ # :attr: system_id (String,nil)
16
+ # The URI corresponding to the system identifier
5
17
  end
6
18
  end
7
19
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  ###
@@ -68,23 +69,27 @@ module Nokogiri
68
69
  NOBASEFIX = 1 << 18
69
70
  # relax any hardcoded limit from the parser
70
71
  HUGE = 1 << 19
72
+ # line numbers stored as long int (instead of a short int)
73
+ BIG_LINES = 1 << 22
71
74
 
72
75
  # the default options used for parsing XML documents
73
- DEFAULT_XML = RECOVER | NONET
76
+ DEFAULT_XML = RECOVER | NONET | BIG_LINES
74
77
  # the default options used for parsing XSLT stylesheets
75
- DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA
78
+ DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA | BIG_LINES
76
79
  # the default options used for parsing HTML documents
77
- DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET
80
+ DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET | BIG_LINES
78
81
  # the default options used for parsing XML schemas
79
- DEFAULT_SCHEMA = NONET
82
+ DEFAULT_SCHEMA = NONET | BIG_LINES
80
83
 
81
84
  attr_accessor :options
82
- def initialize options = STRICT
85
+
86
+ def initialize(options = STRICT)
83
87
  @options = options
84
88
  end
85
89
 
86
90
  constants.each do |constant|
87
91
  next if constant.to_sym == :STRICT
92
+
88
93
  class_eval %{
89
94
  def #{constant.downcase}
90
95
  @options |= #{constant}
@@ -115,14 +120,14 @@ module Nokogiri
115
120
  other.to_i == to_i
116
121
  end
117
122
 
118
- alias :to_i :options
123
+ alias_method :to_i, :options
119
124
 
120
125
  def inspect
121
126
  options = []
122
127
  self.class.constants.each do |k|
123
128
  options << k.downcase if send(:"#{k.downcase}?")
124
129
  end
125
- super.sub(/>$/, " " + options.join(', ') + ">")
130
+ super.sub(/>$/, " " + options.join(", ") + ">")
126
131
  end
127
132
  end
128
133
  end
@@ -1,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
5
+ # :nodoc: all
4
6
  module PP
5
7
  module CharacterData
6
- def pretty_print pp # :nodoc:
7
- nice_name = self.class.name.split('::').last
8
- pp.group(2, "#(#{nice_name} ", ')') do
9
- pp.pp text
8
+ def pretty_print(pp)
9
+ nice_name = self.class.name.split("::").last
10
+ pp.group(2, "#(#{nice_name} ", ")") do
11
+ pp.pp(text)
10
12
  end
11
13
  end
12
14
 
13
- def inspect # :nodoc:
14
- "#<#{self.class.name}:#{sprintf("0x%x",object_id)} #{text.inspect}>"
15
+ def inspect
16
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{text.inspect}>"
15
17
  end
16
18
  end
17
19
  end
@@ -1,54 +1,52 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
5
+ # :nodoc: all
4
6
  module PP
5
7
  module Node
6
- def inspect # :nodoc:
7
- attributes = inspect_attributes.reject { |x|
8
- begin
9
- attribute = send x
10
- !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
11
- rescue NoMethodError
12
- true
13
- end
14
- }.map { |attribute|
15
- "#{attribute.to_s.sub(/_\w+/, 's')}=#{send(attribute).inspect}"
16
- }.join ' '
17
- "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
8
+ def inspect
9
+ attributes = inspect_attributes.reject do |x|
10
+ attribute = send(x)
11
+ !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
12
+ rescue NoMethodError
13
+ true
14
+ end.map do |attribute|
15
+ "#{attribute.to_s.sub(/_\w+/, "s")}=#{send(attribute).inspect}"
16
+ end.join(" ")
17
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{attributes}>"
18
18
  end
19
19
 
20
- def pretty_print pp # :nodoc:
21
- nice_name = self.class.name.split('::').last
22
- pp.group(2, "#(#{nice_name}:#{sprintf("0x%x", object_id)} {", '})') do
23
-
20
+ def pretty_print(pp)
21
+ nice_name = self.class.name.split("::").last
22
+ pp.group(2, "#(#{nice_name}:#{format("0x%x", object_id)} {", "})") do
24
23
  pp.breakable
25
- attrs = inspect_attributes.map { |t|
24
+ attrs = inspect_attributes.map do |t|
26
25
  [t, send(t)] if respond_to?(t)
27
- }.compact.find_all { |x|
26
+ end.compact.find_all do |x|
28
27
  if x.last
29
- if [:attribute_nodes, :children].include? x.first
28
+ if [:attribute_nodes, :children].include?(x.first)
30
29
  !x.last.empty?
31
30
  else
32
31
  true
33
32
  end
34
33
  end
35
- }
34
+ end
36
35
 
37
36
  pp.seplist(attrs) do |v|
38
- if [:attribute_nodes, :children].include? v.first
39
- pp.group(2, "#{v.first.to_s.sub(/_\w+$/, 's')} = [", "]") do
37
+ if [:attribute_nodes, :children].include?(v.first)
38
+ pp.group(2, "#{v.first.to_s.sub(/_\w+$/, "s")} = [", "]") do
40
39
  pp.breakable
41
40
  pp.seplist(v.last) do |item|
42
- pp.pp item
41
+ pp.pp(item)
43
42
  end
44
43
  end
45
44
  else
46
- pp.text "#{v.first} = "
47
- pp.pp v.last
45
+ pp.text("#{v.first} = ")
46
+ pp.pp(v.last)
48
47
  end
49
48
  end
50
49
  pp.breakable
51
-
52
50
  end
53
51
  end
54
52
  end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "pp/node"
3
4
  require_relative "pp/character_data"
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class ProcessingInstruction < Node
5
- def initialize document, name, content
6
+ def initialize(document, name, content) # rubocop:disable Style/RedundantInitialize
6
7
  end
7
8
  end
8
9
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  ###
@@ -8,18 +9,18 @@ module Nokogiri
8
9
  #
9
10
  # Here is an example of usage:
10
11
  #
11
- # reader = Nokogiri::XML::Reader(<<-eoxml)
12
- # <x xmlns:tenderlove='http://tenderlovemaking.com/'>
13
- # <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
14
- # </x>
15
- # eoxml
12
+ # reader = Nokogiri::XML::Reader(<<-eoxml)
13
+ # <x xmlns:tenderlove='http://tenderlovemaking.com/'>
14
+ # <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
15
+ # </x>
16
+ # eoxml
16
17
  #
17
- # reader.each do |node|
18
+ # reader.each do |node|
18
19
  #
19
- # # node is an instance of Nokogiri::XML::Reader
20
- # puts node.name
20
+ # # node is an instance of Nokogiri::XML::Reader
21
+ # puts node.name
21
22
  #
22
- # end
23
+ # end
23
24
  #
24
25
  # Note that Nokogiri::XML::Reader#each can only be called once!! Once
25
26
  # the cursor moves through the entire document, you must parse the
@@ -70,37 +71,32 @@ module Nokogiri
70
71
  # A list of errors encountered while parsing
71
72
  attr_accessor :errors
72
73
 
73
- # The encoding for the document
74
- attr_reader :encoding
75
-
76
74
  # The XML source
77
75
  attr_reader :source
78
76
 
79
- alias :self_closing? :empty_element?
77
+ alias_method :self_closing?, :empty_element?
80
78
 
81
- def initialize source, url = nil, encoding = nil # :nodoc:
79
+ def initialize(source, url = nil, encoding = nil) # :nodoc:
82
80
  @source = source
83
81
  @errors = []
84
82
  @encoding = encoding
85
83
  end
86
84
  private :initialize
87
85
 
88
- ###
89
- # Get the attributes of the current node as a Hash
90
- # @return [Hash<String, String>] Attribute names and values
86
+ # Get the attributes and namespaces of the current node as a Hash.
87
+ #
88
+ # This is the union of Reader#attribute_hash and Reader#namespaces
89
+ #
90
+ # [Returns]
91
+ # (Hash<String, String>) Attribute names and values, and namespace prefixes and hrefs.
91
92
  def attributes
92
- attrs_hash = attribute_nodes.each_with_object({}) do |node, hash|
93
- hash[node.name] = node.to_s
94
- end
95
- ns = namespaces
96
- attrs_hash.merge!(ns) if ns
97
- attrs_hash
93
+ attribute_hash.merge(namespaces)
98
94
  end
99
95
 
100
96
  ###
101
97
  # Move the cursor through the document yielding the cursor to the block
102
98
  def each
103
- while cursor = self.read
99
+ while (cursor = read)
104
100
  yield cursor
105
101
  end
106
102
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module XML
4
5
  class << self