rexml 3.2.6 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,16 +157,16 @@ module REXML
157
157
  if ( @events[@current].matches?(event) )
158
158
  @current += 1
159
159
  if @events[@current].nil?
160
- return @previous.pop
160
+ @previous.pop
161
161
  elsif @events[@current].kind_of? State
162
162
  @current += 1
163
163
  @events[@current-1].previous = self
164
- return @events[@current-1]
164
+ @events[@current-1]
165
165
  else
166
- return self
166
+ self
167
167
  end
168
168
  else
169
- return nil
169
+ nil
170
170
  end
171
171
  end
172
172
 
@@ -186,7 +186,7 @@ module REXML
186
186
  end
187
187
 
188
188
  def expected
189
- return [@events[@current]]
189
+ [@events[@current]]
190
190
  end
191
191
 
192
192
  def <<( event )
@@ -244,7 +244,7 @@ module REXML
244
244
  evt = :end_attribute
245
245
  end
246
246
  end
247
- return Event.new( evt, arg )
247
+ Event.new( evt, arg )
248
248
  end
249
249
  end
250
250
 
@@ -262,9 +262,10 @@ module REXML
262
262
  rv = super
263
263
  return rv if rv
264
264
  @prior = @previous.pop
265
- return @prior.next( event )
265
+ @prior.next( event )
266
+ else
267
+ super
266
268
  end
267
- super
268
269
  end
269
270
 
270
271
  def matches?(event)
@@ -274,7 +275,7 @@ module REXML
274
275
 
275
276
  def expected
276
277
  return [ @prior.expected, @events[0] ].flatten if @current == 0
277
- return [@events[@current]]
278
+ [@events[@current]]
278
279
  end
279
280
  end
280
281
 
@@ -286,24 +287,24 @@ module REXML
286
287
  @current += 1
287
288
  if @events[@current].nil?
288
289
  @current = 0
289
- return self
290
+ self
290
291
  elsif @events[@current].kind_of? State
291
292
  @current += 1
292
293
  @events[@current-1].previous = self
293
- return @events[@current-1]
294
+ @events[@current-1]
294
295
  else
295
- return self
296
+ self
296
297
  end
297
298
  else
298
299
  @prior = @previous.pop
299
300
  return @prior.next( event ) if @current == 0
300
- return nil
301
+ nil
301
302
  end
302
303
  end
303
304
 
304
305
  def expected
305
306
  return [ @prior.expected, @events[0] ].flatten if @current == 0
306
- return [@events[@current]]
307
+ [@events[@current]]
307
308
  end
308
309
  end
309
310
 
@@ -326,17 +327,17 @@ module REXML
326
327
  @ord += 1
327
328
  if @events[@current].nil?
328
329
  @current = 0
329
- return self
330
+ self
330
331
  elsif @events[@current].kind_of? State
331
332
  @current += 1
332
333
  @events[@current-1].previous = self
333
- return @events[@current-1]
334
+ @events[@current-1]
334
335
  else
335
- return self
336
+ self
336
337
  end
337
338
  else
338
339
  return @previous.pop.next( event ) if @current == 0 and @ord > 0
339
- return nil
340
+ nil
340
341
  end
341
342
  end
342
343
 
@@ -347,9 +348,9 @@ module REXML
347
348
 
348
349
  def expected
349
350
  if @current == 0 and @ord > 0
350
- return [@previous[-1].expected, @events[0]].flatten
351
+ [@previous[-1].expected, @events[0]].flatten
351
352
  else
352
- return [@events[@current]]
353
+ [@events[@current]]
353
354
  end
354
355
  end
355
356
  end
@@ -403,7 +404,7 @@ module REXML
403
404
 
404
405
  def expected
405
406
  return [@events[@current]] if @events.size > 0
406
- return @choices.collect do |x|
407
+ @choices.collect do |x|
407
408
  if x[0].kind_of? State
408
409
  x[0].expected
409
410
  else
@@ -490,16 +491,16 @@ module REXML
490
491
  @current += 1
491
492
  if @events[@current].nil?
492
493
  return self unless @choices[@choice].nil?
493
- return @previous.pop
494
+ @previous.pop
494
495
  elsif @events[@current].kind_of? State
495
496
  @current += 1
496
497
  @events[@current-1].previous = self
497
- return @events[@current-1]
498
+ @events[@current-1]
498
499
  else
499
- return self
500
+ self
500
501
  end
501
502
  else
502
- return nil
503
+ nil
503
504
  end
504
505
  end
505
506
 
@@ -510,7 +511,7 @@ module REXML
510
511
 
511
512
  def expected
512
513
  return [@events[@current]] if @events[@current]
513
- return @choices[@choice..-1].collect do |x|
514
+ @choices[@choice..-1].collect do |x|
514
515
  if x[0].kind_of? State
515
516
  x[0].expected
516
517
  else
@@ -80,26 +80,26 @@ module REXML
80
80
  end
81
81
 
82
82
  def single?
83
- return (@event_type != :start_element and @event_type != :start_attribute)
83
+ (@event_type != :start_element and @event_type != :start_attribute)
84
84
  end
85
85
 
86
86
  def matches?( event )
87
87
  return false unless event[0] == @event_type
88
88
  case event[0]
89
89
  when nil
90
- return true
90
+ true
91
91
  when :start_element
92
- return true if event[1] == @event_arg
92
+ event[1] == @event_arg
93
93
  when :end_element
94
- return true
94
+ true
95
95
  when :start_attribute
96
- return true if event[1] == @event_arg
96
+ event[1] == @event_arg
97
97
  when :end_attribute
98
- return true
98
+ true
99
99
  when :end_document
100
- return true
100
+ true
101
101
  when :text
102
- return (@event_arg.nil? or @event_arg == event[1])
102
+ @event_arg.nil? || @event_arg == event[1]
103
103
  =begin
104
104
  when :processing_instruction
105
105
  false
data/lib/rexml/xpath.rb CHANGED
@@ -31,12 +31,7 @@ module REXML
31
31
  def XPath::first(element, path=nil, namespaces=nil, variables={}, options={})
32
32
  raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
33
33
  raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
34
- parser = XPathParser.new(**options)
35
- parser.namespaces = namespaces
36
- parser.variables = variables
37
- path = "*" unless path
38
- element = [element] unless element.kind_of? Array
39
- parser.parse(path, element).flatten[0]
34
+ match(element, path, namespaces, variables, options).flatten[0]
40
35
  end
41
36
 
42
37
  # Iterates over nodes that match the given path, calling the supplied
@@ -60,12 +55,7 @@ module REXML
60
55
  def XPath::each(element, path=nil, namespaces=nil, variables={}, options={}, &block)
61
56
  raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
62
57
  raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
63
- parser = XPathParser.new(**options)
64
- parser.namespaces = namespaces
65
- parser.variables = variables
66
- path = "*" unless path
67
- element = [element] unless element.kind_of? Array
68
- parser.parse(path, element).each( &block )
58
+ match(element, path, namespaces, variables, options).each( &block )
69
59
  end
70
60
 
71
61
  # Returns an array of nodes matching a given XPath.
@@ -74,7 +64,6 @@ module REXML
74
64
  parser.namespaces = namespaces
75
65
  parser.variables = variables
76
66
  path = "*" unless path
77
- element = [element] unless element.kind_of? Array
78
67
  parser.parse(path,element)
79
68
  end
80
69
  end
@@ -76,19 +76,32 @@ module REXML
76
76
  @variables = vars
77
77
  end
78
78
 
79
- def parse path, nodeset
79
+ def parse path, node
80
80
  path_stack = @parser.parse( path )
81
- match( path_stack, nodeset )
81
+ if node.is_a?(Array)
82
+ Kernel.warn("REXML::XPath.each, REXML::XPath.first, REXML::XPath.match dropped support for nodeset...", uplevel: 1)
83
+ return [] if node.empty?
84
+ node = node.first
85
+ end
86
+
87
+ document = node.document
88
+ if document
89
+ document.__send__(:enable_cache) do
90
+ match( path_stack, node )
91
+ end
92
+ else
93
+ match( path_stack, node )
94
+ end
82
95
  end
83
96
 
84
- def get_first path, nodeset
97
+ def get_first path, node
85
98
  path_stack = @parser.parse( path )
86
- first( path_stack, nodeset )
99
+ first( path_stack, node )
87
100
  end
88
101
 
89
- def predicate path, nodeset
102
+ def predicate path, node
90
103
  path_stack = @parser.parse( path )
91
- match( path_stack, nodeset )
104
+ match( path_stack, node )
92
105
  end
93
106
 
94
107
  def []=( variable_name, value )
@@ -106,7 +119,7 @@ module REXML
106
119
  case path[0]
107
120
  when :document
108
121
  # do nothing
109
- return first( path[1..-1], node )
122
+ first( path[1..-1], node )
110
123
  when :child
111
124
  for c in node.children
112
125
  r = first( path[1..-1], c )
@@ -116,9 +129,9 @@ module REXML
116
129
  name = path[2]
117
130
  if node.name == name
118
131
  return node if path.size == 3
119
- return first( path[3..-1], node )
132
+ first( path[3..-1], node )
120
133
  else
121
- return nil
134
+ nil
122
135
  end
123
136
  when :descendant_or_self
124
137
  r = first( path[1..-1], node )
@@ -128,23 +141,21 @@ module REXML
128
141
  return r if r
129
142
  end
130
143
  when :node
131
- return first( path[1..-1], node )
144
+ first( path[1..-1], node )
132
145
  when :any
133
- return first( path[1..-1], node )
146
+ first( path[1..-1], node )
147
+ else
148
+ nil
134
149
  end
135
- return nil
136
150
  end
137
151
 
138
152
 
139
- def match(path_stack, nodeset)
140
- nodeset = nodeset.collect.with_index do |node, i|
141
- position = i + 1
142
- XPathNode.new(node, position: position)
143
- end
153
+ def match(path_stack, node)
154
+ nodeset = [XPathNode.new(node, position: 1)]
144
155
  result = expr(path_stack, nodeset)
145
156
  case result
146
157
  when Array # nodeset
147
- unnode(result)
158
+ unnode(result).uniq
148
159
  else
149
160
  [result]
150
161
  end
@@ -162,10 +173,10 @@ module REXML
162
173
  # 2. If no mapping was supplied, use the context node to look up the namespace
163
174
  def get_namespace( node, prefix )
164
175
  if @namespaces
165
- return @namespaces[prefix] || ''
176
+ @namespaces[prefix] || ''
166
177
  else
167
178
  return node.namespace( prefix ) if node.node_type == :element
168
- return ''
179
+ ''
169
180
  end
170
181
  end
171
182
 
@@ -492,14 +503,10 @@ module REXML
492
503
  if strict?
493
504
  raw_node.name == name and raw_node.namespace == ""
494
505
  else
495
- # FIXME: This DOUBLES the time XPath searches take
496
- ns = get_namespace(raw_node, prefix)
497
- raw_node.name == name and raw_node.namespace == ns
506
+ raw_node.name == name and raw_node.namespace == get_namespace(raw_node, prefix)
498
507
  end
499
508
  else
500
- # FIXME: This DOUBLES the time XPath searches take
501
- ns = get_namespace(raw_node, prefix)
502
- raw_node.name == name and raw_node.namespace == ns
509
+ raw_node.name == name and raw_node.namespace == get_namespace(raw_node, prefix)
503
510
  end
504
511
  when :attribute
505
512
  if prefix.nil?
@@ -507,9 +514,7 @@ module REXML
507
514
  elsif prefix.empty?
508
515
  raw_node.name == name and raw_node.namespace == ""
509
516
  else
510
- # FIXME: This DOUBLES the time XPath searches take
511
- ns = get_namespace(raw_node.element, prefix)
512
- raw_node.name == name and raw_node.namespace == ns
517
+ raw_node.name == name and raw_node.namespace == get_namespace(raw_node.element, prefix)
513
518
  end
514
519
  else
515
520
  false
@@ -590,6 +595,7 @@ module REXML
590
595
 
591
596
  def evaluate_predicate(expression, nodesets)
592
597
  enter(:predicate, expression, nodesets) if @debug
598
+ new_nodeset_count = 0
593
599
  new_nodesets = nodesets.collect do |nodeset|
594
600
  new_nodeset = []
595
601
  subcontext = { :size => nodeset.size }
@@ -606,17 +612,20 @@ module REXML
606
612
  result = result[0] if result.kind_of? Array and result.length == 1
607
613
  if result.kind_of? Numeric
608
614
  if result == node.position
609
- new_nodeset << XPathNode.new(node, position: new_nodeset.size + 1)
615
+ new_nodeset_count += 1
616
+ new_nodeset << XPathNode.new(node, position: new_nodeset_count)
610
617
  end
611
618
  elsif result.instance_of? Array
612
619
  if result.size > 0 and result.inject(false) {|k,s| s or k}
613
620
  if result.size > 0
614
- new_nodeset << XPathNode.new(node, position: new_nodeset.size + 1)
621
+ new_nodeset_count += 1
622
+ new_nodeset << XPathNode.new(node, position: new_nodeset_count)
615
623
  end
616
624
  end
617
625
  else
618
626
  if result
619
- new_nodeset << XPathNode.new(node, position: new_nodeset.size + 1)
627
+ new_nodeset_count += 1
628
+ new_nodeset << XPathNode.new(node, position: new_nodeset_count)
620
629
  end
621
630
  end
622
631
  end
@@ -667,7 +676,7 @@ module REXML
667
676
  if order == :forward
668
677
  index
669
678
  else
670
- -index
679
+ index.map(&:-@)
671
680
  end
672
681
  end
673
682
  ordered.collect do |_index, node|
@@ -754,22 +763,19 @@ module REXML
754
763
  end
755
764
 
756
765
  def following_node_of( node )
757
- if node.kind_of? Element and node.children.size > 0
758
- return node.children[0]
759
- end
760
- return next_sibling_node(node)
766
+ return node.children[0] if node.kind_of?(Element) and node.children.size > 0
767
+
768
+ next_sibling_node(node)
761
769
  end
762
770
 
763
771
  def next_sibling_node(node)
764
772
  psn = node.next_sibling_node
765
773
  while psn.nil?
766
- if node.parent.nil? or node.parent.class == Document
767
- return nil
768
- end
774
+ return nil if node.parent.nil? or node.parent.class == Document
769
775
  node = node.parent
770
776
  psn = node.next_sibling_node
771
777
  end
772
- return psn
778
+ psn
773
779
  end
774
780
 
775
781
  def child(nodeset)
@@ -802,13 +808,13 @@ module REXML
802
808
  def norm b
803
809
  case b
804
810
  when true, false
805
- return b
811
+ b
806
812
  when 'true', 'false'
807
- return Functions::boolean( b )
813
+ Functions::boolean( b )
808
814
  when /^\d+(\.\d+)?$/, Numeric
809
- return Functions::number( b )
815
+ Functions::number( b )
810
816
  else
811
- return Functions::string( b )
817
+ Functions::string( b )
812
818
  end
813
819
  end
814
820
 
metadata CHANGED
@@ -1,57 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-07-27 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: test-unit
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
55
12
  description: An XML toolkit for Ruby
56
13
  email:
57
14
  - kou@cozmixng.org
@@ -144,8 +101,8 @@ files:
144
101
  homepage: https://github.com/ruby/rexml
145
102
  licenses:
146
103
  - BSD-2-Clause
147
- metadata: {}
148
- post_install_message:
104
+ metadata:
105
+ changelog_uri: https://github.com/ruby/rexml/releases/tag/v3.4.2
149
106
  rdoc_options:
150
107
  - "--main"
151
108
  - README.md
@@ -162,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
119
  - !ruby/object:Gem::Version
163
120
  version: '0'
164
121
  requirements: []
165
- rubygems_version: 3.5.0.dev
166
- signing_key:
122
+ rubygems_version: 3.6.9
167
123
  specification_version: 4
168
124
  summary: An XML toolkit for Ruby
169
125
  test_files: []