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.
- checksums.yaml +4 -4
- data/NEWS.md +525 -0
- data/lib/rexml/attribute.rb +10 -10
- 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 +23 -5
- data/lib/rexml/element.rb +63 -84
- data/lib/rexml/encoding.rb +3 -6
- data/lib/rexml/entity.rb +9 -48
- data/lib/rexml/formatters/pretty.rb +1 -1
- data/lib/rexml/functions.rb +4 -5
- data/lib/rexml/instruction.rb +1 -1
- data/lib/rexml/namespace.rb +4 -4
- data/lib/rexml/node.rb +10 -6
- data/lib/rexml/parseexception.rb +1 -0
- data/lib/rexml/parsers/baseparser.rb +538 -288
- data/lib/rexml/parsers/pullparser.rb +16 -0
- data/lib/rexml/parsers/sax2parser.rb +16 -19
- data/lib/rexml/parsers/streamparser.rb +16 -10
- data/lib/rexml/parsers/treeparser.rb +9 -21
- 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 +190 -100
- data/lib/rexml/text.rb +68 -74
- 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 +51 -45
- metadata +6 -50
@@ -47,6 +47,18 @@ module REXML
|
|
47
47
|
@listeners << listener
|
48
48
|
end
|
49
49
|
|
50
|
+
def entity_expansion_count
|
51
|
+
@parser.entity_expansion_count
|
52
|
+
end
|
53
|
+
|
54
|
+
def entity_expansion_limit=( limit )
|
55
|
+
@parser.entity_expansion_limit = limit
|
56
|
+
end
|
57
|
+
|
58
|
+
def entity_expansion_text_limit=( limit )
|
59
|
+
@parser.entity_expansion_text_limit = limit
|
60
|
+
end
|
61
|
+
|
50
62
|
def each
|
51
63
|
while has_next?
|
52
64
|
yield self.pull
|
@@ -81,6 +93,10 @@ module REXML
|
|
81
93
|
def unshift token
|
82
94
|
@my_stack.unshift token
|
83
95
|
end
|
96
|
+
|
97
|
+
def reset
|
98
|
+
@parser.reset
|
99
|
+
end
|
84
100
|
end
|
85
101
|
|
86
102
|
# A parsing event. The contents of the event are accessed as an +Array?,
|
@@ -22,6 +22,18 @@ module REXML
|
|
22
22
|
@parser.source
|
23
23
|
end
|
24
24
|
|
25
|
+
def entity_expansion_count
|
26
|
+
@parser.entity_expansion_count
|
27
|
+
end
|
28
|
+
|
29
|
+
def entity_expansion_limit=( limit )
|
30
|
+
@parser.entity_expansion_limit = limit
|
31
|
+
end
|
32
|
+
|
33
|
+
def entity_expansion_text_limit=( limit )
|
34
|
+
@parser.entity_expansion_text_limit = limit
|
35
|
+
end
|
36
|
+
|
25
37
|
def add_listener( listener )
|
26
38
|
@parser.add_listener( listener )
|
27
39
|
end
|
@@ -157,25 +169,8 @@ module REXML
|
|
157
169
|
end
|
158
170
|
end
|
159
171
|
when :text
|
160
|
-
|
161
|
-
|
162
|
-
copy = event[1].clone
|
163
|
-
|
164
|
-
esub = proc { |match|
|
165
|
-
if @entities.has_key?($1)
|
166
|
-
@entities[$1].gsub(Text::REFERENCE, &esub)
|
167
|
-
else
|
168
|
-
match
|
169
|
-
end
|
170
|
-
}
|
171
|
-
|
172
|
-
copy.gsub!( Text::REFERENCE, &esub )
|
173
|
-
copy.gsub!( Text::NUMERICENTITY ) {|m|
|
174
|
-
m=$1
|
175
|
-
m = "0#{m}" if m[0] == ?x
|
176
|
-
[Integer(m)].pack('U*')
|
177
|
-
}
|
178
|
-
handle( :characters, copy )
|
172
|
+
unnormalized = @parser.unnormalize( event[1], @entities )
|
173
|
+
handle( :characters, unnormalized )
|
179
174
|
when :entitydecl
|
180
175
|
handle_entitydecl( event )
|
181
176
|
when :processing_instruction, :comment, :attlistdecl,
|
@@ -264,6 +259,8 @@ module REXML
|
|
264
259
|
end
|
265
260
|
|
266
261
|
def get_namespace( prefix )
|
262
|
+
return nil if @namespace_stack.empty?
|
263
|
+
|
267
264
|
uris = (@namespace_stack.find_all { |ns| not ns[prefix].nil? }) ||
|
268
265
|
(@namespace_stack.find { |ns| not ns[nil].nil? })
|
269
266
|
uris[-1][prefix] unless uris.nil? or 0 == uris.size
|
@@ -7,37 +7,42 @@ module REXML
|
|
7
7
|
def initialize source, listener
|
8
8
|
@listener = listener
|
9
9
|
@parser = BaseParser.new( source )
|
10
|
-
@
|
10
|
+
@entities = {}
|
11
11
|
end
|
12
12
|
|
13
13
|
def add_listener( listener )
|
14
14
|
@parser.add_listener( listener )
|
15
15
|
end
|
16
16
|
|
17
|
+
def entity_expansion_count
|
18
|
+
@parser.entity_expansion_count
|
19
|
+
end
|
20
|
+
|
21
|
+
def entity_expansion_limit=( limit )
|
22
|
+
@parser.entity_expansion_limit = limit
|
23
|
+
end
|
24
|
+
|
25
|
+
def entity_expansion_text_limit=( limit )
|
26
|
+
@parser.entity_expansion_text_limit = limit
|
27
|
+
end
|
28
|
+
|
17
29
|
def parse
|
18
30
|
# entity string
|
19
31
|
while true
|
20
32
|
event = @parser.pull
|
21
33
|
case event[0]
|
22
34
|
when :end_document
|
23
|
-
unless @tag_stack.empty?
|
24
|
-
tag_path = "/" + @tag_stack.join("/")
|
25
|
-
raise ParseException.new("Missing end tag for '#{tag_path}'",
|
26
|
-
@parser.source)
|
27
|
-
end
|
28
35
|
return
|
29
36
|
when :start_element
|
30
|
-
@tag_stack << event[1]
|
31
37
|
attrs = event[2].each do |n, v|
|
32
38
|
event[2][n] = @parser.unnormalize( v )
|
33
39
|
end
|
34
40
|
@listener.tag_start( event[1], attrs )
|
35
41
|
when :end_element
|
36
42
|
@listener.tag_end( event[1] )
|
37
|
-
@tag_stack.pop
|
38
43
|
when :text
|
39
|
-
|
40
|
-
@listener.text(
|
44
|
+
unnormalized = @parser.unnormalize( event[1], @entities )
|
45
|
+
@listener.text( unnormalized )
|
41
46
|
when :processing_instruction
|
42
47
|
@listener.instruction( *event[1,2] )
|
43
48
|
when :start_doctype
|
@@ -48,6 +53,7 @@ module REXML
|
|
48
53
|
when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
|
49
54
|
@listener.send( event[0].to_s, *event[1..-1] )
|
50
55
|
when :entitydecl, :notationdecl
|
56
|
+
@entities[ event[1] ] = event[2] if event.size == 3
|
51
57
|
@listener.send( event[0].to_s, event[1..-1] )
|
52
58
|
when :externalentity
|
53
59
|
entity_reference = event[1]
|
@@ -15,8 +15,6 @@ module REXML
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def parse
|
18
|
-
tag_stack = []
|
19
|
-
in_doctype = false
|
20
18
|
entities = nil
|
21
19
|
begin
|
22
20
|
while true
|
@@ -24,32 +22,24 @@ module REXML
|
|
24
22
|
#STDERR.puts "TREEPARSER GOT #{event.inspect}"
|
25
23
|
case event[0]
|
26
24
|
when :end_document
|
27
|
-
unless tag_stack.empty?
|
28
|
-
raise ParseException.new("No close tag for #{@build_context.xpath}",
|
29
|
-
@parser.source, @parser)
|
30
|
-
end
|
31
25
|
return
|
32
26
|
when :start_element
|
33
|
-
tag_stack.push(event[1])
|
34
27
|
el = @build_context = @build_context.add_element( event[1] )
|
35
28
|
event[2].each do |key, value|
|
36
29
|
el.attributes[key]=Attribute.new(key,value,self)
|
37
30
|
end
|
38
31
|
when :end_element
|
39
|
-
tag_stack.pop
|
40
32
|
@build_context = @build_context.parent
|
41
33
|
when :text
|
42
|
-
if
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@build_context.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
)
|
52
|
-
end
|
34
|
+
if @build_context[-1].instance_of? Text
|
35
|
+
@build_context[-1] << event[1]
|
36
|
+
else
|
37
|
+
@build_context.add(
|
38
|
+
Text.new(event[1], @build_context.whitespace, nil, true)
|
39
|
+
) unless (
|
40
|
+
@build_context.ignore_whitespace_nodes and
|
41
|
+
event[1].strip.size==0
|
42
|
+
)
|
53
43
|
end
|
54
44
|
when :comment
|
55
45
|
c = Comment.new( event[1] )
|
@@ -60,14 +50,12 @@ module REXML
|
|
60
50
|
when :processing_instruction
|
61
51
|
@build_context.add( Instruction.new( event[1], event[2] ) )
|
62
52
|
when :end_doctype
|
63
|
-
in_doctype = false
|
64
53
|
entities.each { |k,v| entities[k] = @build_context.entities[k].value }
|
65
54
|
@build_context = @build_context.parent
|
66
55
|
when :start_doctype
|
67
56
|
doctype = DocType.new( event[1..-1], @build_context )
|
68
57
|
@build_context = doctype
|
69
58
|
entities = {}
|
70
|
-
in_doctype = true
|
71
59
|
when :attlistdecl
|
72
60
|
n = AttlistDecl.new( event[1..-1] )
|
73
61
|
@build_context.add( n )
|
@@ -215,7 +215,7 @@ module REXML
|
|
215
215
|
else
|
216
216
|
path << yield( parsed )
|
217
217
|
end
|
218
|
-
|
218
|
+
path.squeeze(" ")
|
219
219
|
end
|
220
220
|
# For backward compatibility
|
221
221
|
alias_method :preciate_to_string, :predicate_to_path
|
@@ -252,7 +252,7 @@ module REXML
|
|
252
252
|
path = path[1..-1]
|
253
253
|
end
|
254
254
|
end
|
255
|
-
|
255
|
+
RelativeLocationPath( path, parsed ) if path.size > 0
|
256
256
|
end
|
257
257
|
|
258
258
|
#RelativeLocationPath
|
@@ -388,7 +388,7 @@ module REXML
|
|
388
388
|
else
|
389
389
|
path = original_path
|
390
390
|
end
|
391
|
-
|
391
|
+
path
|
392
392
|
end
|
393
393
|
|
394
394
|
# Filters the supplied nodeset on the predicate(s)
|
@@ -600,7 +600,7 @@ module REXML
|
|
600
600
|
end
|
601
601
|
rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/
|
602
602
|
parsed.concat(n)
|
603
|
-
|
603
|
+
rest
|
604
604
|
end
|
605
605
|
|
606
606
|
#| FilterExpr Predicate
|
data/lib/rexml/quickpath.rb
CHANGED
@@ -41,7 +41,7 @@ module REXML
|
|
41
41
|
else
|
42
42
|
results = filter([element], path)
|
43
43
|
end
|
44
|
-
|
44
|
+
results
|
45
45
|
end
|
46
46
|
|
47
47
|
# Given an array of nodes it filters the array based on the path. The
|
@@ -51,18 +51,18 @@ module REXML
|
|
51
51
|
return elements if path.nil? or path == '' or elements.size == 0
|
52
52
|
case path
|
53
53
|
when /^\/\//u # Descendant
|
54
|
-
|
54
|
+
axe( elements, "descendant-or-self", $' )
|
55
55
|
when /^\/?\b(\w[-\w]*)\b::/u # Axe
|
56
|
-
|
56
|
+
axe( elements, $1, $' )
|
57
57
|
when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
|
58
58
|
rest = $'
|
59
59
|
results = []
|
60
60
|
elements.each do |element|
|
61
61
|
results |= filter( element.to_a, rest )
|
62
62
|
end
|
63
|
-
|
63
|
+
results
|
64
64
|
when /^\/?(\w[-\w]*)\(/u # / Function
|
65
|
-
|
65
|
+
function( elements, $1, $' )
|
66
66
|
when Namespace::NAMESPLIT # Element name
|
67
67
|
name = $2
|
68
68
|
ns = $1
|
@@ -73,21 +73,21 @@ module REXML
|
|
73
73
|
(element.name == name and
|
74
74
|
element.namespace == Functions.namespace_context[ns])))
|
75
75
|
end
|
76
|
-
|
76
|
+
filter( elements, rest )
|
77
77
|
when /^\/\[/u
|
78
78
|
matches = []
|
79
79
|
elements.each do |element|
|
80
80
|
matches |= predicate( element.to_a, path[1..-1] ) if element.kind_of? Element
|
81
81
|
end
|
82
|
-
|
82
|
+
matches
|
83
83
|
when /^\[/u # Predicate
|
84
|
-
|
84
|
+
predicate( elements, path )
|
85
85
|
when /^\/?\.\.\./u # Ancestor
|
86
|
-
|
86
|
+
axe( elements, "ancestor", $' )
|
87
87
|
when /^\/?\.\./u # Parent
|
88
|
-
|
88
|
+
filter( elements.collect{|e|e.parent}, $' )
|
89
89
|
when /^\/?\./u # Self
|
90
|
-
|
90
|
+
filter( elements, $' )
|
91
91
|
when /^\*/u # Any
|
92
92
|
results = []
|
93
93
|
elements.each do |element|
|
@@ -98,9 +98,10 @@ module REXML
|
|
98
98
|
# results |= filter( children, $' )
|
99
99
|
#end
|
100
100
|
end
|
101
|
-
|
101
|
+
results
|
102
|
+
else
|
103
|
+
[]
|
102
104
|
end
|
103
|
-
return []
|
104
105
|
end
|
105
106
|
|
106
107
|
def QuickPath::axe( elements, axe_name, rest )
|
@@ -138,7 +139,7 @@ module REXML
|
|
138
139
|
matches = filter(elements.collect{|element|
|
139
140
|
element.previous_sibling}.uniq, rest )
|
140
141
|
end
|
141
|
-
|
142
|
+
matches.uniq
|
142
143
|
end
|
143
144
|
|
144
145
|
OPERAND_ = '((?=(?:(?!and|or).)*[^\s<>=])[^\s<>=]+)'
|
@@ -200,15 +201,15 @@ module REXML
|
|
200
201
|
results << element
|
201
202
|
end
|
202
203
|
end
|
203
|
-
|
204
|
+
filter( results, rest )
|
204
205
|
end
|
205
206
|
|
206
207
|
def QuickPath::attribute( name )
|
207
|
-
|
208
|
+
Functions.node.attributes[name] if Functions.node.kind_of? Element
|
208
209
|
end
|
209
210
|
|
210
211
|
def QuickPath::name()
|
211
|
-
|
212
|
+
Functions.node.name if Functions.node.kind_of? Element
|
212
213
|
end
|
213
214
|
|
214
215
|
def QuickPath::method_missing( id, *args )
|
@@ -234,7 +235,7 @@ module REXML
|
|
234
235
|
results << element if Functions.pair[0] == res
|
235
236
|
end
|
236
237
|
end
|
237
|
-
|
238
|
+
results
|
238
239
|
end
|
239
240
|
|
240
241
|
def QuickPath::parse_args( element, string )
|
data/lib/rexml/rexml.rb
CHANGED
data/lib/rexml/security.rb
CHANGED
@@ -10,7 +10,7 @@ module REXML
|
|
10
10
|
|
11
11
|
# Get the entity expansion limit. By default the limit is set to 10000.
|
12
12
|
def self.entity_expansion_limit
|
13
|
-
|
13
|
+
@@entity_expansion_limit
|
14
14
|
end
|
15
15
|
|
16
16
|
@@entity_expansion_text_limit = 10_240
|
@@ -22,7 +22,7 @@ module REXML
|
|
22
22
|
|
23
23
|
# Get the entity expansion limit. By default the limit is set to 10240.
|
24
24
|
def self.entity_expansion_text_limit
|
25
|
-
|
25
|
+
@@entity_expansion_text_limit
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|