nokogiri 1.12.5 → 1.13.6
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +9 -7
- data/bin/nokogiri +63 -50
- data/dependencies.yml +13 -64
- data/ext/nokogiri/extconf.rb +64 -44
- data/ext/nokogiri/html4_sax_parser_context.c +2 -3
- data/ext/nokogiri/xml_document.c +35 -35
- data/ext/nokogiri/xml_document_fragment.c +0 -2
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_encoding_handler.c +25 -11
- data/ext/nokogiri/xml_node.c +638 -333
- data/ext/nokogiri/xml_reader.c +37 -11
- data/ext/nokogiri/xml_sax_parser_context.c +10 -3
- data/ext/nokogiri/xml_xpath_context.c +72 -49
- data/ext/nokogiri/xslt_stylesheet.c +107 -9
- data/gumbo-parser/src/parser.c +0 -11
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +360 -341
- data/lib/nokogiri/css/parser.y +249 -244
- data/lib/nokogiri/css/parser_extras.rb +22 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +4 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +179 -82
- data/lib/nokogiri/css.rb +38 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +88 -77
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +5 -2
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +11 -5
- data/lib/nokogiri/html5/document.rb +27 -10
- data/lib/nokogiri/html5/document_fragment.rb +5 -2
- data/lib/nokogiri/html5/node.rb +10 -3
- data/lib/nokogiri/html5.rb +69 -64
- data/lib/nokogiri/jruby/dependencies.rb +10 -9
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +20 -13
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +5 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +34 -32
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +144 -103
- data/lib/nokogiri/xml/document_fragment.rb +41 -38
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +2 -0
- data/lib/nokogiri/xml/node/save_options.rb +8 -4
- data/lib/nokogiri/xml/node.rb +521 -351
- data/lib/nokogiri/xml/node_set.rb +50 -54
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +12 -7
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +24 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/reader.rb +17 -19
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +37 -34
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +93 -62
- data/lib/nokogiri/xml/syntax_error.rb +5 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +4 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +21 -13
- data/lib/nokogiri.rb +19 -16
- data/lib/xsd/xmlparser/nokogiri.rb +25 -24
- data/patches/libxml2/0004-use-glibc-strlen.patch +3 -3
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2443 -1914
- data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +61 -0
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
- data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
- metadata +109 -31
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- 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
|
-
|
16
|
+
alias_method :clone, :dup
|
16
17
|
|
17
18
|
# Create a NodeSet with +document+ defaulting to +list+
|
18
|
-
def initialize
|
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
|
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
|
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
|
61
|
-
first.before
|
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
|
67
|
-
last.after
|
68
|
+
def after(datum)
|
69
|
+
last.after(datum)
|
68
70
|
end
|
69
71
|
|
70
|
-
|
71
|
-
|
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
|
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
|
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
|
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
|
-
|
125
|
+
alias_method :%, :at
|
131
126
|
|
132
127
|
###
|
133
128
|
# Filter this list for nodes that match +expr+
|
134
|
-
def filter
|
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
|
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
|
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
|
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
|
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 ||
|
211
|
+
node[k] = v || yield(node)
|
217
212
|
end
|
218
213
|
end
|
219
214
|
|
220
215
|
self
|
221
216
|
end
|
222
|
-
|
223
|
-
|
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
|
228
|
-
each { |el| el.delete
|
222
|
+
def remove_attr(name)
|
223
|
+
each { |el| el.delete(name) }
|
229
224
|
self
|
230
225
|
end
|
231
|
-
|
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
|
-
|
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
|
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
|
271
|
-
map { |node| node.wrap
|
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
|
277
|
+
def to_html(*args)
|
283
278
|
if Nokogiri.jruby?
|
284
279
|
options = args.first.is_a?(Hash) ? args.shift : {}
|
285
|
-
|
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
|
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
|
296
|
+
def to_xml(*args)
|
302
297
|
map { |x| x.to_xml(*args) }.join
|
303
298
|
end
|
304
299
|
|
305
|
-
|
306
|
-
|
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
|
-
|
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
|
-
|
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 ==
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
7
|
-
nice_name = self.class.name.split(
|
8
|
-
pp.group(2, "#(#{nice_name} ",
|
9
|
-
pp.pp
|
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
|
14
|
-
"#<#{self.class.name}:#{
|
15
|
+
def inspect
|
16
|
+
"#<#{self.class.name}:#{format("0x%x", object_id)} #{text.inspect}>"
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/nokogiri/xml/pp/node.rb
CHANGED
@@ -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
|
7
|
-
attributes = inspect_attributes.reject
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
21
|
-
nice_name = self.class.name.split(
|
22
|
-
pp.group(2, "#(#{nice_name}:#{
|
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
|
24
|
+
attrs = inspect_attributes.map do |t|
|
26
25
|
[t, send(t)] if respond_to?(t)
|
27
|
-
|
26
|
+
end.compact.find_all do |x|
|
28
27
|
if x.last
|
29
|
-
if [:attribute_nodes, :children].include?
|
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?
|
39
|
-
pp.group(2, "#{v.first.to_s.sub(/_\w+$/,
|
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
|
41
|
+
pp.pp(item)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
else
|
46
|
-
pp.text
|
47
|
-
pp.pp
|
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
|
data/lib/nokogiri/xml/pp.rb
CHANGED
data/lib/nokogiri/xml/reader.rb
CHANGED
@@ -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
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
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
|
-
#
|
18
|
+
# reader.each do |node|
|
18
19
|
#
|
19
|
-
#
|
20
|
-
#
|
20
|
+
# # node is an instance of Nokogiri::XML::Reader
|
21
|
+
# puts node.name
|
21
22
|
#
|
22
|
-
#
|
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,28 +71,25 @@ 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
|
-
|
77
|
+
alias_method :self_closing?, :empty_element?
|
80
78
|
|
81
|
-
def initialize
|
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
86
|
# Get the attributes of the current node as a Hash
|
90
|
-
#
|
87
|
+
#
|
88
|
+
# [Returns] (Hash<String, String>) Attribute names and values
|
91
89
|
def attributes
|
92
90
|
attrs_hash = attribute_nodes.each_with_object({}) do |node, hash|
|
93
|
-
|
94
|
-
|
91
|
+
hash[node.name] = node.to_s
|
92
|
+
end
|
95
93
|
ns = namespaces
|
96
94
|
attrs_hash.merge!(ns) if ns
|
97
95
|
attrs_hash
|
@@ -100,7 +98,7 @@ module Nokogiri
|
|
100
98
|
###
|
101
99
|
# Move the cursor through the document yielding the cursor to the block
|
102
100
|
def each
|
103
|
-
while cursor =
|
101
|
+
while (cursor = read)
|
104
102
|
yield cursor
|
105
103
|
end
|
106
104
|
end
|