rjr 0.16.5 → 0.16.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rjr/common.rb +18 -12
- metadata +1 -1
data/lib/rjr/common.rb
CHANGED
@@ -188,7 +188,7 @@ class Class
|
|
188
188
|
end
|
189
189
|
|
190
190
|
module RJR
|
191
|
-
def self.
|
191
|
+
def self.invalid_json_class?(jc)
|
192
192
|
Class.whitelist_json_classes ||= false
|
193
193
|
|
194
194
|
Class.whitelist_json_classes ?
|
@@ -209,29 +209,35 @@ module RJR
|
|
209
209
|
|
210
210
|
def self.validate_json_hash(jh)
|
211
211
|
jh.each { |k,v|
|
212
|
-
if k == ::JSON.create_id &&
|
213
|
-
validate_json_class(v)
|
212
|
+
if k == ::JSON.create_id && invalid_json_class?(v)
|
214
213
|
raise ArgumentError, "can't create json class #{v}"
|
215
214
|
elsif v.is_a?(Array)
|
216
|
-
v
|
217
|
-
if vi.is_a?(Hash)
|
218
|
-
validate_json_hash(vi)
|
219
|
-
end
|
220
|
-
}
|
215
|
+
validate_json_array(v)
|
221
216
|
elsif v.is_a?(Hash)
|
222
217
|
validate_json_hash(v)
|
223
218
|
end
|
224
219
|
}
|
225
220
|
end
|
221
|
+
|
222
|
+
def self.validate_json_array(ja)
|
223
|
+
ja.each { |jai|
|
224
|
+
if jai.is_a?(Array)
|
225
|
+
validate_json_array(jai)
|
226
|
+
elsif jai.is_a?(Hash)
|
227
|
+
validate_json_hash(jai)
|
228
|
+
end
|
229
|
+
}
|
230
|
+
end
|
226
231
|
|
227
232
|
def self.parse_json(js)
|
228
233
|
jp = ::JSON.parse js, :create_additions => false
|
229
234
|
if jp.is_a?(Array)
|
230
|
-
jp
|
231
|
-
elsif
|
232
|
-
|
235
|
+
validate_json_array(jp)
|
236
|
+
elsif jp.is_a?(Hash)
|
237
|
+
validate_json_hash(jp)
|
238
|
+
else
|
239
|
+
return jp
|
233
240
|
end
|
234
|
-
validate_json_hash(jp)
|
235
241
|
::JSON.parse js, :create_additions => true
|
236
242
|
end
|
237
243
|
end
|