rexml 3.3.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70ccd1465a05dba3d53dcfc4a98e76dec865a4f6ac833b954aff4234bce6c255
4
- data.tar.gz: 53f43fab8f531e0ba7461ce091e5eae6bec27b12e9139450c7b3e748b4eeacdc
3
+ metadata.gz: 582bb5339257c81f2ce9c076155c01d7adfe8fb169c09bc7f5f489f6a76bca80
4
+ data.tar.gz: 160de8899d8d1f995bafca23631e9e4ab928ebbffa21684e3b61dad805a6187b
5
5
  SHA512:
6
- metadata.gz: b46818d79ae57075c4e0bd620802e82c6958dddc7da1b182504c3fdc16685c887ac0ddd6a4838a080483abba330839e9ef4b2db22cc81b9eae3eac71ac14c965
7
- data.tar.gz: 1e5205905eb435c02038dd0539de22472f5364ffc47635f13a1752cb79a423dcca558fb47394ac5d624b358e779b07cbcafedfd06b99742026856f9988109976
6
+ metadata.gz: e2b095792523f54301e8a6af2f1682a9ad24d92cdd5d94c9e6088b27520e3c03b68fe06061b6ff2fd96b001b9cb947c57e4095244d83206a83fc2a1829dd4243
7
+ data.tar.gz: 4f335d2b1e58c1da233c3f0a0588def502c8cb2660633e0e06b4d0930bbcedcaae36b52dc550923704b4525d94a1011f4b5f4e87a81e5d689cce24ee89210a23
data/NEWS.md CHANGED
@@ -1,5 +1,202 @@
1
1
  # News
2
2
 
3
+ ## 3.4.0 - 2024-12-15 {#version-3-4-0}
4
+
5
+ ### Improvement
6
+
7
+ * Improved performance.
8
+ * GH-216
9
+ * Patch by NAITOH Jun
10
+
11
+ * JRuby: Improved parse performance.
12
+ * GH-219
13
+ * Patch by João Duarte
14
+
15
+ * Added support for reusing pull parser.
16
+ * GH-214
17
+ * GH-220
18
+ * Patch by Dmitry Pogrebnoy
19
+
20
+ * Improved error handling when source is `IO`.
21
+ * GH-221
22
+ * Patch by NAITOH Jun
23
+
24
+ ### Thanks
25
+
26
+ * NAITOH Jun
27
+
28
+ * João Duarte
29
+
30
+ * Dmitry Pogrebnoy
31
+
32
+ ## 3.3.9 - 2024-10-24 {#version-3-3-9}
33
+
34
+ ### Improvements
35
+
36
+ * Improved performance.
37
+ * GH-210
38
+ * Patch by NAITOH Jun.
39
+
40
+ ### Fixes
41
+
42
+ * Fixed a parse bug for text only invalid XML.
43
+ * GH-215
44
+ * Patch by NAITOH Jun.
45
+
46
+ * Fixed a parse bug that `&#0x...;` is accepted as a character
47
+ reference.
48
+
49
+ ### Thanks
50
+
51
+ * NAITOH Jun
52
+
53
+ ## 3.3.8 - 2024-09-29 {#version-3-3-8}
54
+
55
+ ### Improvements
56
+
57
+ * SAX2: Improve parse performance.
58
+ * GH-207
59
+ * Patch by NAITOH Jun.
60
+
61
+ ### Fixes
62
+
63
+ * Fixed a bug that unexpected attribute namespace conflict error for
64
+ the predefined "xml" namespace is reported.
65
+ * GH-208
66
+ * Patch by KITAITI Makoto
67
+
68
+ ### Thanks
69
+
70
+ * NAITOH Jun
71
+
72
+ * KITAITI Makoto
73
+
74
+ ## 3.3.7 - 2024-09-04 {#version-3-3-7}
75
+
76
+ ### Improvements
77
+
78
+ * Added local entity expansion limit methods
79
+ * GH-192
80
+ * GH-202
81
+ * Reported by takuya kodama.
82
+ * Patch by NAITOH Jun.
83
+
84
+ * Removed explicit strscan dependency
85
+ * GH-204
86
+ * Patch by Bo Anderson.
87
+
88
+ ### Thanks
89
+
90
+ * takuya kodama
91
+
92
+ * NAITOH Jun
93
+
94
+ * Bo Anderson
95
+
96
+ ## 3.3.6 - 2024-08-22 {#version-3-3-6}
97
+
98
+ ### Improvements
99
+
100
+ * Removed duplicated entity expansions for performance.
101
+ * GH-194
102
+ * Patch by Viktor Ivarsson.
103
+
104
+ * Improved namespace conflicted attribute check performance. It was
105
+ too slow for deep elements.
106
+ * Reported by l33thaxor.
107
+
108
+ ### Fixes
109
+
110
+ * Fixed a bug that default entity expansions are counted for
111
+ security check. Default entity expansions should not be counted
112
+ because they don't have a security risk.
113
+ * GH-198
114
+ * GH-199
115
+ * Patch Viktor Ivarsson
116
+
117
+ * Fixed a parser bug that parameter entity references in internal
118
+ subsets are expanded. It's not allowed in the XML specification.
119
+ * GH-191
120
+ * Patch by NAITOH Jun.
121
+
122
+ * Fixed a stream parser bug that user-defined entity references in
123
+ text aren't expanded.
124
+ * GH-200
125
+ * Patch by NAITOH Jun.
126
+
127
+ ### Thanks
128
+
129
+ * Viktor Ivarsson
130
+
131
+ * NAITOH Jun
132
+
133
+ * l33thaxor
134
+
135
+ ## 3.3.5 - 2024-08-12 {#version-3-3-5}
136
+
137
+ ### Fixes
138
+
139
+ * Fixed a bug that `REXML::Security.entity_expansion_text_limit`
140
+ check has wrong text size calculation in SAX and pull parsers.
141
+ * GH-193
142
+ * GH-195
143
+ * Reported by Viktor Ivarsson.
144
+ * Patch by NAITOH Jun.
145
+
146
+ ### Thanks
147
+
148
+ * Viktor Ivarsson
149
+
150
+ * NAITOH Jun
151
+
152
+ ## 3.3.4 - 2024-08-01 {#version-3-3-4}
153
+
154
+ ### Fixes
155
+
156
+ * Fixed a bug that `REXML::Security` isn't defined when
157
+ `REXML::Parsers::StreamParser` is used and
158
+ `rexml/parsers/streamparser` is only required.
159
+ * GH-189
160
+ * Patch by takuya kodama.
161
+
162
+ ### Thanks
163
+
164
+ * takuya kodama
165
+
166
+ ## 3.3.3 - 2024-08-01 {#version-3-3-3}
167
+
168
+ ### Improvements
169
+
170
+ * Added support for detecting invalid XML that has unsupported
171
+ content before root element
172
+ * GH-184
173
+ * Patch by NAITOH Jun.
174
+
175
+ * Added support for `REXML::Security.entity_expansion_limit=` and
176
+ `REXML::Security.entity_expansion_text_limit=` in SAX2 and pull
177
+ parsers
178
+ * GH-187
179
+ * Patch by NAITOH Jun.
180
+
181
+ * Added more tests for invalid XMLs.
182
+ * GH-183
183
+ * Patch by Watson.
184
+
185
+ * Added more performance tests.
186
+ * Patch by Watson.
187
+
188
+ * Improved parse performance.
189
+ * GH-186
190
+ * Patch by tomoya ishida.
191
+
192
+ ### Thanks
193
+
194
+ * NAITOH Jun
195
+
196
+ * Watson
197
+
198
+ * tomoya ishida
199
+
3
200
  ## 3.3.2 - 2024-07-16 {#version-3-3-2}
4
201
 
5
202
  ### Improvements
@@ -15,6 +212,9 @@
15
212
  * GH-172
16
213
  * GH-173
17
214
  * GH-174
215
+ * GH-175
216
+ * GH-176
217
+ * GH-177
18
218
  * Patch by Watson.
19
219
 
20
220
  * Added support for raising a parse exception when an XML has extra
@@ -148,8 +148,9 @@ module REXML
148
148
  # have been expanded to their values
149
149
  def value
150
150
  return @unnormalized if @unnormalized
151
- @unnormalized = Text::unnormalize( @normalized, doctype )
152
- @unnormalized
151
+
152
+ @unnormalized = Text::unnormalize(@normalized, doctype,
153
+ entity_expansion_text_limit: @element&.document&.entity_expansion_text_limit)
153
154
  end
154
155
 
155
156
  # The normalized value of this attribute. That is, the attribute with
@@ -91,6 +91,8 @@ module REXML
91
91
  #
92
92
  def initialize( source = nil, context = {} )
93
93
  @entity_expansion_count = 0
94
+ @entity_expansion_limit = Security.entity_expansion_limit
95
+ @entity_expansion_text_limit = Security.entity_expansion_text_limit
94
96
  super()
95
97
  @context = context
96
98
  return if source.nil?
@@ -431,10 +433,12 @@ module REXML
431
433
  end
432
434
 
433
435
  attr_reader :entity_expansion_count
436
+ attr_writer :entity_expansion_limit
437
+ attr_accessor :entity_expansion_text_limit
434
438
 
435
439
  def record_entity_expansion
436
440
  @entity_expansion_count += 1
437
- if @entity_expansion_count > Security.entity_expansion_limit
441
+ if @entity_expansion_count > @entity_expansion_limit
438
442
  raise "number of entity expansions exceeded, processing aborted."
439
443
  end
440
444
  end
data/lib/rexml/element.rb CHANGED
@@ -441,9 +441,14 @@ module REXML
441
441
  # Related: #root_node, #document.
442
442
  #
443
443
  def root
444
- return elements[1] if self.kind_of? Document
445
- return self if parent.kind_of? Document or parent.nil?
446
- return parent.root
444
+ target = self
445
+ while target
446
+ return target.elements[1] if target.kind_of? Document
447
+ parent = target.parent
448
+ return target if parent.kind_of? Document or parent.nil?
449
+ target = parent
450
+ end
451
+ nil
447
452
  end
448
453
 
449
454
  # :call-seq:
@@ -619,8 +624,12 @@ module REXML
619
624
  else
620
625
  prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
621
626
  end
622
- ns = attributes[ prefix ]
623
- ns = parent.namespace(prefix) if ns.nil? and parent
627
+ ns = nil
628
+ target = self
629
+ while ns.nil? and target
630
+ ns = target.attributes[prefix]
631
+ target = target.parent
632
+ end
624
633
  ns = '' if ns.nil? and prefix == 'xmlns'
625
634
  return ns
626
635
  end
@@ -2375,17 +2384,6 @@ module REXML
2375
2384
  elsif old_attr.kind_of? Hash
2376
2385
  old_attr[value.prefix] = value
2377
2386
  elsif old_attr.prefix != value.prefix
2378
- # Check for conflicting namespaces
2379
- if value.prefix != "xmlns" and old_attr.prefix != "xmlns"
2380
- old_namespace = old_attr.namespace
2381
- new_namespace = value.namespace
2382
- if old_namespace == new_namespace
2383
- raise ParseException.new(
2384
- "Namespace conflict in adding attribute \"#{value.name}\": "+
2385
- "Prefix \"#{old_attr.prefix}\" = \"#{old_namespace}\" and "+
2386
- "prefix \"#{value.prefix}\" = \"#{new_namespace}\"")
2387
- end
2388
- end
2389
2387
  store value.name, {old_attr.prefix => old_attr,
2390
2388
  value.prefix => value}
2391
2389
  else
data/lib/rexml/entity.rb CHANGED
@@ -12,6 +12,7 @@ module REXML
12
12
  EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))"
13
13
  NDATADECL = "\\s+NDATA\\s+#{NAME}"
14
14
  PEREFERENCE = "%#{NAME};"
15
+ PEREFERENCE_RE = /#{PEREFERENCE}/um
15
16
  ENTITYVALUE = %Q{((?:"(?:[^%&"]|#{PEREFERENCE}|#{REFERENCE})*")|(?:'([^%&']|#{PEREFERENCE}|#{REFERENCE})*'))}
16
17
  PEDEF = "(?:#{ENTITYVALUE}|#{EXTERNALID})"
17
18
  ENTITYDEF = "(?:#{ENTITYVALUE}|(?:#{EXTERNALID}(#{NDATADECL})?))"
@@ -19,7 +20,7 @@ module REXML
19
20
  GEDECL = "<!ENTITY\\s+#{NAME}\\s+#{ENTITYDEF}\\s*>"
20
21
  ENTITYDECL = /\s*(?:#{GEDECL})|(?:#{PEDECL})/um
21
22
 
22
- attr_reader :name, :external, :ref, :ndata, :pubid
23
+ attr_reader :name, :external, :ref, :ndata, :pubid, :value
23
24
 
24
25
  # Create a new entity. Simple entities can be constructed by passing a
25
26
  # name, value to the constructor; this creates a generic, plain entity
@@ -68,14 +69,14 @@ module REXML
68
69
  end
69
70
 
70
71
  # Evaluates to the unnormalized value of this entity; that is, replacing
71
- # all entities -- both %ent; and &ent; entities. This differs from
72
- # +value()+ in that +value+ only replaces %ent; entities.
72
+ # &ent; entities.
73
73
  def unnormalized
74
- document.record_entity_expansion unless document.nil?
75
- v = value()
76
- return nil if v.nil?
77
- @unnormalized = Text::unnormalize(v, parent)
78
- @unnormalized
74
+ document&.record_entity_expansion
75
+
76
+ return nil if @value.nil?
77
+
78
+ @unnormalized = Text::unnormalize(@value, parent,
79
+ entity_expansion_text_limit: document&.entity_expansion_text_limit)
79
80
  end
80
81
 
81
82
  #once :unnormalized
@@ -121,46 +122,6 @@ module REXML
121
122
  write rv
122
123
  rv
123
124
  end
124
-
125
- PEREFERENCE_RE = /#{PEREFERENCE}/um
126
- # Returns the value of this entity. At the moment, only internal entities
127
- # are processed. If the value contains internal references (IE,
128
- # %blah;), those are replaced with their values. IE, if the doctype
129
- # contains:
130
- # <!ENTITY % foo "bar">
131
- # <!ENTITY yada "nanoo %foo; nanoo>
132
- # then:
133
- # doctype.entity('yada').value #-> "nanoo bar nanoo"
134
- def value
135
- @resolved_value ||= resolve_value
136
- end
137
-
138
- def parent=(other)
139
- @resolved_value = nil
140
- super
141
- end
142
-
143
- private
144
- def resolve_value
145
- return nil if @value.nil?
146
- return @value unless @value.match?(PEREFERENCE_RE)
147
-
148
- matches = @value.scan(PEREFERENCE_RE)
149
- rv = @value.clone
150
- if @parent
151
- sum = 0
152
- matches.each do |entity_reference|
153
- entity_value = @parent.entity( entity_reference[0] )
154
- if sum + entity_value.bytesize > Security.entity_expansion_text_limit
155
- raise "entity expansion has grown too large"
156
- else
157
- sum += entity_value.bytesize
158
- end
159
- rv.gsub!( /%#{entity_reference.join};/um, entity_value )
160
- end
161
- end
162
- rv
163
- end
164
125
  end
165
126
 
166
127
  # This is a set of entity constants -- the ones defined in the XML