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.
- checksums.yaml +4 -4
- data/NEWS.md +240 -1
- data/lib/rexml/attribute.rb +7 -8
- data/lib/rexml/cdata.rb +1 -1
- data/lib/rexml/child.rb +2 -3
- data/lib/rexml/comment.rb +1 -1
- data/lib/rexml/doctype.rb +3 -8
- data/lib/rexml/document.rb +21 -5
- data/lib/rexml/element.rb +53 -59
- data/lib/rexml/encoding.rb +3 -6
- data/lib/rexml/functions.rb +3 -3
- data/lib/rexml/instruction.rb +1 -1
- data/lib/rexml/namespace.rb +4 -4
- data/lib/rexml/node.rb +2 -2
- data/lib/rexml/parsers/baseparser.rb +211 -118
- data/lib/rexml/parsers/pullparser.rb +4 -0
- data/lib/rexml/parsers/sax2parser.rb +2 -0
- data/lib/rexml/parsers/xpathparser.rb +4 -4
- data/lib/rexml/quickpath.rb +19 -18
- data/lib/rexml/rexml.rb +1 -1
- data/lib/rexml/security.rb +2 -2
- data/lib/rexml/source.rb +68 -8
- data/lib/rexml/text.rb +29 -57
- data/lib/rexml/validation/relaxng.rb +27 -26
- data/lib/rexml/validation/validation.rb +8 -8
- data/lib/rexml/xpath.rb +2 -13
- data/lib/rexml/xpath_parser.rb +44 -42
- metadata +4 -4
data/lib/rexml/element.rb
CHANGED
|
@@ -473,8 +473,7 @@ module REXML
|
|
|
473
473
|
# Related: #root, #root_node.
|
|
474
474
|
#
|
|
475
475
|
def document
|
|
476
|
-
|
|
477
|
-
rt.parent if rt
|
|
476
|
+
root&.parent
|
|
478
477
|
end
|
|
479
478
|
|
|
480
479
|
# :call-seq:
|
|
@@ -566,7 +565,7 @@ module REXML
|
|
|
566
565
|
prefixes = []
|
|
567
566
|
prefixes = parent.prefixes if parent
|
|
568
567
|
prefixes |= attributes.prefixes
|
|
569
|
-
|
|
568
|
+
prefixes
|
|
570
569
|
end
|
|
571
570
|
|
|
572
571
|
# :call-seq:
|
|
@@ -589,10 +588,12 @@ module REXML
|
|
|
589
588
|
# d.elements['//c'].namespaces # => {"x"=>"1", "y"=>"2", "z"=>"3"}
|
|
590
589
|
#
|
|
591
590
|
def namespaces
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
591
|
+
namespaces_cache = document&.__send__(:namespaces_cache)
|
|
592
|
+
if namespaces_cache
|
|
593
|
+
namespaces_cache[self] ||= calculate_namespaces
|
|
594
|
+
else
|
|
595
|
+
calculate_namespaces
|
|
596
|
+
end
|
|
596
597
|
end
|
|
597
598
|
|
|
598
599
|
# :call-seq:
|
|
@@ -619,19 +620,11 @@ module REXML
|
|
|
619
620
|
if prefix.nil?
|
|
620
621
|
prefix = prefix()
|
|
621
622
|
end
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
|
|
626
|
-
end
|
|
627
|
-
ns = nil
|
|
628
|
-
target = self
|
|
629
|
-
while ns.nil? and target
|
|
630
|
-
ns = target.attributes[prefix]
|
|
631
|
-
target = target.parent
|
|
632
|
-
end
|
|
623
|
+
prefix = (prefix == '') ? 'xmlns' : prefix.delete_prefix("xmlns:")
|
|
624
|
+
ns = namespaces[prefix]
|
|
625
|
+
|
|
633
626
|
ns = '' if ns.nil? and prefix == 'xmlns'
|
|
634
|
-
|
|
627
|
+
ns
|
|
635
628
|
end
|
|
636
629
|
|
|
637
630
|
# :call-seq:
|
|
@@ -963,7 +956,7 @@ module REXML
|
|
|
963
956
|
def next_element
|
|
964
957
|
element = next_sibling
|
|
965
958
|
element = element.next_sibling until element.nil? or element.kind_of? Element
|
|
966
|
-
|
|
959
|
+
element
|
|
967
960
|
end
|
|
968
961
|
|
|
969
962
|
# :call-seq:
|
|
@@ -979,7 +972,7 @@ module REXML
|
|
|
979
972
|
def previous_element
|
|
980
973
|
element = previous_sibling
|
|
981
974
|
element = element.previous_sibling until element.nil? or element.kind_of? Element
|
|
982
|
-
|
|
975
|
+
element
|
|
983
976
|
end
|
|
984
977
|
|
|
985
978
|
|
|
@@ -1029,8 +1022,7 @@ module REXML
|
|
|
1029
1022
|
#
|
|
1030
1023
|
def text( path = nil )
|
|
1031
1024
|
rv = get_text(path)
|
|
1032
|
-
|
|
1033
|
-
nil
|
|
1025
|
+
rv&.value
|
|
1034
1026
|
end
|
|
1035
1027
|
|
|
1036
1028
|
# :call-seq:
|
|
@@ -1058,7 +1050,7 @@ module REXML
|
|
|
1058
1050
|
else
|
|
1059
1051
|
rv = @children.find { |node| node.kind_of? Text }
|
|
1060
1052
|
end
|
|
1061
|
-
|
|
1053
|
+
rv
|
|
1062
1054
|
end
|
|
1063
1055
|
|
|
1064
1056
|
# :call-seq:
|
|
@@ -1102,7 +1094,7 @@ module REXML
|
|
|
1102
1094
|
old_text.replace_with( text )
|
|
1103
1095
|
end
|
|
1104
1096
|
end
|
|
1105
|
-
|
|
1097
|
+
self
|
|
1106
1098
|
end
|
|
1107
1099
|
|
|
1108
1100
|
# :call-seq:
|
|
@@ -1153,7 +1145,7 @@ module REXML
|
|
|
1153
1145
|
text = Text.new( text, whitespace(), nil, raw() )
|
|
1154
1146
|
end
|
|
1155
1147
|
self << text unless text.nil?
|
|
1156
|
-
|
|
1148
|
+
self
|
|
1157
1149
|
end
|
|
1158
1150
|
|
|
1159
1151
|
# :call-seq:
|
|
@@ -1197,7 +1189,7 @@ module REXML
|
|
|
1197
1189
|
cur = cur.parent
|
|
1198
1190
|
path_elements << __to_xpath_helper( cur )
|
|
1199
1191
|
end
|
|
1200
|
-
|
|
1192
|
+
path_elements.reverse.join( "/" )
|
|
1201
1193
|
end
|
|
1202
1194
|
|
|
1203
1195
|
#################################################
|
|
@@ -1299,7 +1291,6 @@ module REXML
|
|
|
1299
1291
|
return nil unless ( namespaces[ prefix ] == namespaces[ 'xmlns' ] )
|
|
1300
1292
|
|
|
1301
1293
|
attributes.get_attribute( name )
|
|
1302
|
-
|
|
1303
1294
|
end
|
|
1304
1295
|
|
|
1305
1296
|
# :call-seq:
|
|
@@ -1313,7 +1304,7 @@ module REXML
|
|
|
1313
1304
|
# b.has_attributes? # => false
|
|
1314
1305
|
#
|
|
1315
1306
|
def has_attributes?
|
|
1316
|
-
|
|
1307
|
+
!@attributes.empty?
|
|
1317
1308
|
end
|
|
1318
1309
|
|
|
1319
1310
|
# :call-seq:
|
|
@@ -1502,7 +1493,7 @@ module REXML
|
|
|
1502
1493
|
# doc.write( out ) #-> doc is written to the string 'out'
|
|
1503
1494
|
# doc.write( $stdout ) #-> doc written to the console
|
|
1504
1495
|
def write(output=$stdout, indent=-1, transitive=false, ie_hack=false)
|
|
1505
|
-
Kernel.warn("#{self.class.name}
|
|
1496
|
+
Kernel.warn("#{self.class.name}#write is deprecated. See REXML::Formatters", uplevel: 1)
|
|
1506
1497
|
formatter = if indent > -1
|
|
1507
1498
|
if transitive
|
|
1508
1499
|
require_relative "formatters/transitive"
|
|
@@ -1516,8 +1507,15 @@ module REXML
|
|
|
1516
1507
|
formatter.write( self, output )
|
|
1517
1508
|
end
|
|
1518
1509
|
|
|
1519
|
-
|
|
1520
1510
|
private
|
|
1511
|
+
def calculate_namespaces
|
|
1512
|
+
if parent
|
|
1513
|
+
parent.namespaces.merge(attributes.namespaces)
|
|
1514
|
+
else
|
|
1515
|
+
attributes.namespaces
|
|
1516
|
+
end
|
|
1517
|
+
end
|
|
1518
|
+
|
|
1521
1519
|
def __to_xpath_helper node
|
|
1522
1520
|
rv = node.expanded_name.clone
|
|
1523
1521
|
if node.parent
|
|
@@ -1684,11 +1682,7 @@ module REXML
|
|
|
1684
1682
|
(num += 1) == index
|
|
1685
1683
|
}
|
|
1686
1684
|
else
|
|
1687
|
-
|
|
1688
|
-
#{ |element|
|
|
1689
|
-
# return element if element.kind_of? Element
|
|
1690
|
-
#}
|
|
1691
|
-
#return nil
|
|
1685
|
+
XPath::first( @element, index )
|
|
1692
1686
|
end
|
|
1693
1687
|
end
|
|
1694
1688
|
|
|
@@ -1735,7 +1729,7 @@ module REXML
|
|
|
1735
1729
|
else
|
|
1736
1730
|
previous.replace_with element
|
|
1737
1731
|
end
|
|
1738
|
-
|
|
1732
|
+
previous
|
|
1739
1733
|
end
|
|
1740
1734
|
|
|
1741
1735
|
# :call-seq:
|
|
@@ -1774,7 +1768,7 @@ module REXML
|
|
|
1774
1768
|
child == element
|
|
1775
1769
|
end
|
|
1776
1770
|
return rv if found == element
|
|
1777
|
-
|
|
1771
|
+
-1
|
|
1778
1772
|
end
|
|
1779
1773
|
|
|
1780
1774
|
# :call-seq:
|
|
@@ -1853,7 +1847,7 @@ module REXML
|
|
|
1853
1847
|
@element.delete element
|
|
1854
1848
|
element.remove
|
|
1855
1849
|
end
|
|
1856
|
-
|
|
1850
|
+
rv
|
|
1857
1851
|
end
|
|
1858
1852
|
|
|
1859
1853
|
# :call-seq:
|
|
@@ -2180,8 +2174,7 @@ module REXML
|
|
|
2180
2174
|
#
|
|
2181
2175
|
def [](name)
|
|
2182
2176
|
attr = get_attribute(name)
|
|
2183
|
-
|
|
2184
|
-
return nil
|
|
2177
|
+
attr&.value
|
|
2185
2178
|
end
|
|
2186
2179
|
|
|
2187
2180
|
# :call-seq:
|
|
@@ -2324,11 +2317,11 @@ module REXML
|
|
|
2324
2317
|
return attr
|
|
2325
2318
|
end
|
|
2326
2319
|
end
|
|
2327
|
-
|
|
2328
|
-
if
|
|
2320
|
+
doctype = @element.document&.doctype
|
|
2321
|
+
if doctype
|
|
2329
2322
|
expn = @element.expanded_name
|
|
2330
|
-
expn =
|
|
2331
|
-
attr_val =
|
|
2323
|
+
expn = doctype.name if expn.size == 0
|
|
2324
|
+
attr_val = doctype.attribute_of(expn, name)
|
|
2332
2325
|
return Attribute.new( name, attr_val ) if attr_val
|
|
2333
2326
|
end
|
|
2334
2327
|
return nil
|
|
@@ -2336,7 +2329,7 @@ module REXML
|
|
|
2336
2329
|
if attr.kind_of? Hash
|
|
2337
2330
|
attr = attr[ @element.prefix ]
|
|
2338
2331
|
end
|
|
2339
|
-
|
|
2332
|
+
attr
|
|
2340
2333
|
end
|
|
2341
2334
|
|
|
2342
2335
|
# :call-seq:
|
|
@@ -2370,8 +2363,9 @@ module REXML
|
|
|
2370
2363
|
end
|
|
2371
2364
|
|
|
2372
2365
|
unless value.kind_of? Attribute
|
|
2373
|
-
|
|
2374
|
-
|
|
2366
|
+
doctype = @element.document&.doctype
|
|
2367
|
+
if doctype
|
|
2368
|
+
value = Text::normalize( value, doctype )
|
|
2375
2369
|
else
|
|
2376
2370
|
value = Text::normalize( value, nil )
|
|
2377
2371
|
end
|
|
@@ -2389,7 +2383,7 @@ module REXML
|
|
|
2389
2383
|
else
|
|
2390
2384
|
store value.name, value
|
|
2391
2385
|
end
|
|
2392
|
-
|
|
2386
|
+
@element
|
|
2393
2387
|
end
|
|
2394
2388
|
|
|
2395
2389
|
# :call-seq:
|
|
@@ -2408,10 +2402,11 @@ module REXML
|
|
|
2408
2402
|
each_attribute do |attribute|
|
|
2409
2403
|
ns << attribute.name if attribute.prefix == 'xmlns'
|
|
2410
2404
|
end
|
|
2411
|
-
|
|
2405
|
+
doctype = @element.document&.doctype
|
|
2406
|
+
if doctype
|
|
2412
2407
|
expn = @element.expanded_name
|
|
2413
|
-
expn =
|
|
2414
|
-
|
|
2408
|
+
expn = doctype.name if expn.size == 0
|
|
2409
|
+
doctype.attributes_of(expn).each {
|
|
2415
2410
|
|attribute|
|
|
2416
2411
|
ns << attribute.name if attribute.prefix == 'xmlns'
|
|
2417
2412
|
}
|
|
@@ -2433,10 +2428,11 @@ module REXML
|
|
|
2433
2428
|
each_attribute do |attribute|
|
|
2434
2429
|
namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
|
|
2435
2430
|
end
|
|
2436
|
-
|
|
2431
|
+
doctype = @element.document&.doctype
|
|
2432
|
+
if doctype
|
|
2437
2433
|
expn = @element.expanded_name
|
|
2438
|
-
expn =
|
|
2439
|
-
|
|
2434
|
+
expn = doctype.name if expn.size == 0
|
|
2435
|
+
doctype.attributes_of(expn).each {
|
|
2440
2436
|
|attribute|
|
|
2441
2437
|
namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
|
|
2442
2438
|
}
|
|
@@ -2491,9 +2487,7 @@ module REXML
|
|
|
2491
2487
|
old.each_value{|v| repl = v}
|
|
2492
2488
|
store name, repl
|
|
2493
2489
|
end
|
|
2494
|
-
elsif old
|
|
2495
|
-
return @element
|
|
2496
|
-
else # the supplied attribute is a top-level one
|
|
2490
|
+
elsif old # the supplied attribute is a top-level one
|
|
2497
2491
|
super(name)
|
|
2498
2492
|
end
|
|
2499
2493
|
@element
|
|
@@ -2547,7 +2541,7 @@ module REXML
|
|
|
2547
2541
|
rv << attribute if attribute.expanded_name == name
|
|
2548
2542
|
}
|
|
2549
2543
|
rv.each{ |attr| attr.remove }
|
|
2550
|
-
|
|
2544
|
+
rv
|
|
2551
2545
|
end
|
|
2552
2546
|
|
|
2553
2547
|
# :call-seq:
|
data/lib/rexml/encoding.rb
CHANGED
|
@@ -5,7 +5,7 @@ module REXML
|
|
|
5
5
|
# ID ---> Encoding name
|
|
6
6
|
attr_reader :encoding
|
|
7
7
|
def encoding=(encoding)
|
|
8
|
-
encoding = encoding.name if encoding.is_a?(Encoding)
|
|
8
|
+
encoding = encoding.name if encoding.is_a?(::Encoding)
|
|
9
9
|
if encoding.is_a?(String)
|
|
10
10
|
original_encoding = encoding
|
|
11
11
|
encoding = find_encoding(encoding)
|
|
@@ -13,12 +13,9 @@ module REXML
|
|
|
13
13
|
raise ArgumentError, "Bad encoding name #{original_encoding}"
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
+
encoding = encoding.upcase if encoding
|
|
16
17
|
return false if defined?(@encoding) and encoding == @encoding
|
|
17
|
-
|
|
18
|
-
@encoding = encoding.upcase
|
|
19
|
-
else
|
|
20
|
-
@encoding = 'UTF-8'
|
|
21
|
-
end
|
|
18
|
+
@encoding = encoding || "UTF-8"
|
|
22
19
|
true
|
|
23
20
|
end
|
|
24
21
|
|
data/lib/rexml/functions.rb
CHANGED
|
@@ -39,11 +39,11 @@ module REXML
|
|
|
39
39
|
|
|
40
40
|
def Functions::text( )
|
|
41
41
|
if @@context[:node].node_type == :element
|
|
42
|
-
|
|
42
|
+
@@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
|
|
43
43
|
elsif @@context[:node].node_type == :text
|
|
44
|
-
|
|
44
|
+
@@context[:node].value
|
|
45
45
|
else
|
|
46
|
-
|
|
46
|
+
false
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
data/lib/rexml/instruction.rb
CHANGED
|
@@ -49,7 +49,7 @@ module REXML
|
|
|
49
49
|
# See the rexml/formatters package
|
|
50
50
|
#
|
|
51
51
|
def write writer, indent=-1, transitive=false, ie_hack=false
|
|
52
|
-
Kernel.warn( "#{self.class.name}
|
|
52
|
+
Kernel.warn( "#{self.class.name}#write is deprecated", uplevel: 1)
|
|
53
53
|
indent(writer, indent)
|
|
54
54
|
writer << START
|
|
55
55
|
writer << @target
|
data/lib/rexml/namespace.rb
CHANGED
|
@@ -42,11 +42,11 @@ module REXML
|
|
|
42
42
|
# Compares names optionally WITH namespaces
|
|
43
43
|
def has_name?( other, ns=nil )
|
|
44
44
|
if ns
|
|
45
|
-
|
|
45
|
+
namespace() == ns and name() == other
|
|
46
46
|
elsif other.include? ":"
|
|
47
|
-
|
|
47
|
+
fully_expanded_name == other
|
|
48
48
|
else
|
|
49
|
-
|
|
49
|
+
name == other
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -57,7 +57,7 @@ module REXML
|
|
|
57
57
|
def fully_expanded_name
|
|
58
58
|
ns = prefix
|
|
59
59
|
return "#{ns}:#@name" if ns.size > 0
|
|
60
|
-
|
|
60
|
+
@name
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
data/lib/rexml/node.rb
CHANGED
|
@@ -26,7 +26,7 @@ module REXML
|
|
|
26
26
|
# REXML::Formatters package for changing the output style.
|
|
27
27
|
def to_s indent=nil
|
|
28
28
|
unless indent.nil?
|
|
29
|
-
Kernel.warn( "#{self.class.name}
|
|
29
|
+
Kernel.warn( "#{self.class.name}#to_s(indent) parameter is deprecated", uplevel: 1)
|
|
30
30
|
f = REXML::Formatters::Pretty.new( indent )
|
|
31
31
|
f.write( self, rv = "" )
|
|
32
32
|
else
|
|
@@ -68,7 +68,7 @@ module REXML
|
|
|
68
68
|
each_recursive {|node|
|
|
69
69
|
return node if block.call(node)
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
nil
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# Returns the position that +self+ holds in its parent's array, indexed
|