rexml 3.3.7 → 3.4.4

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.
@@ -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
@@ -671,7 +676,7 @@ module REXML
671
676
  if order == :forward
672
677
  index
673
678
  else
674
- -index
679
+ index.map(&:-@)
675
680
  end
676
681
  end
677
682
  ordered.collect do |_index, node|
@@ -758,22 +763,19 @@ module REXML
758
763
  end
759
764
 
760
765
  def following_node_of( node )
761
- if node.kind_of? Element and node.children.size > 0
762
- return node.children[0]
763
- end
764
- 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)
765
769
  end
766
770
 
767
771
  def next_sibling_node(node)
768
772
  psn = node.next_sibling_node
769
773
  while psn.nil?
770
- if node.parent.nil? or node.parent.class == Document
771
- return nil
772
- end
774
+ return nil if node.parent.nil? or node.parent.class == Document
773
775
  node = node.parent
774
776
  psn = node.next_sibling_node
775
777
  end
776
- return psn
778
+ psn
777
779
  end
778
780
 
779
781
  def child(nodeset)
@@ -806,13 +808,13 @@ module REXML
806
808
  def norm b
807
809
  case b
808
810
  when true, false
809
- return b
811
+ b
810
812
  when 'true', 'false'
811
- return Functions::boolean( b )
813
+ Functions::boolean( b )
812
814
  when /^\d+(\.\d+)?$/, Numeric
813
- return Functions::number( b )
815
+ Functions::number( b )
814
816
  else
815
- return Functions::string( b )
817
+ Functions::string( b )
816
818
  end
817
819
  end
818
820
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.7
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-09-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: An XML toolkit for Ruby
13
13
  email:
@@ -102,7 +102,7 @@ homepage: https://github.com/ruby/rexml
102
102
  licenses:
103
103
  - BSD-2-Clause
104
104
  metadata:
105
- changelog_uri: https://github.com/ruby/rexml/releases/tag/v3.3.7
105
+ changelog_uri: https://github.com/ruby/rexml/releases/tag/v3.4.4
106
106
  rdoc_options:
107
107
  - "--main"
108
108
  - README.md
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubygems_version: 3.6.0.dev
122
+ rubygems_version: 3.6.9
123
123
  specification_version: 4
124
124
  summary: An XML toolkit for Ruby
125
125
  test_files: []