oj-safe 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5db75d52595ff977025eb4746986c3e640f865fb0e022dc979cad6a1ebbf4c59
4
- data.tar.gz: fffe75b048a7b2f9a583517b038c3d4f14d592f8d860a880f851a7c3cc352f30
3
+ metadata.gz: 02c5aa00ec358c39f60b008cb8d0beeac926b5635eda855df53e98df453aa425
4
+ data.tar.gz: cd7db2bab94dc7286b1c9cedfa6e3fa2a6edf31ce67527530c7424d6e9006af2
5
5
  SHA512:
6
- metadata.gz: 989dae91a64a063661d2a761b72bd5f0e7b593a157123131ab06ead18092098801b21b22031cc3f8a483206d06edeb530d1d28892df31562d12f8b791be3e4eb
7
- data.tar.gz: 9d9b2c822fbce6dad86f969f653217462af714f79e1a757cbde2fb14cfb062977b436ff844ea81cf31b50ba66a1c90e43795a16878a4d59cc9941d8c2ce3c5d1
6
+ metadata.gz: 9bc912c849561867cf7d780f9654e1c2a5df0605fea8e46eaa8d83417a5abe52d4cd9b3602a480ea7b52460cd5ad863f9a34ea852b97d18e269f04ae46908f1a
7
+ data.tar.gz: 3519be24f916efe79432313b1af5d37992d5ddfcfaee9bec3b5b07fb5bda33757e8ddc914b8349592bbdf76cc69c689bfe0509159120301baee701976ca45550
data/ext/oj-safe/safe.c CHANGED
@@ -19,7 +19,11 @@ static VALUE max_hash_size_sym,
19
19
  max_depth_sym,
20
20
  max_total_elements_sym,
21
21
  max_json_size_bytes_sym,
22
- validation_error_class;
22
+ max_hash_size_error_class,
23
+ max_array_size_error_class,
24
+ max_depth_error_class,
25
+ max_total_elements_error_class,
26
+ max_json_size_error_class;
23
27
 
24
28
  static ID parser_ivar_id,
25
29
  parse_id,
@@ -74,7 +78,7 @@ static void check_object_size(safe_T safe) {
74
78
 
75
79
  if(safe->max_hash_size > number_of_items_in_hash) return;
76
80
 
77
- rb_raise(validation_error_class, "Too many object items!");
81
+ rb_raise(max_hash_size_error_class, "Too many object items!");
78
82
  }
79
83
 
80
84
  static void check_array_size(safe_T safe) {
@@ -88,13 +92,13 @@ static void check_array_size(safe_T safe) {
88
92
 
89
93
  if(safe->max_array_size > number_of_items_in_array) return;
90
94
 
91
- rb_raise(validation_error_class, "Too many array items!");
95
+ rb_raise(max_array_size_error_class, "Too many array items!");
92
96
  }
93
97
 
94
98
  static void check_max_depth(safe_T safe, ojParser p) {
95
99
  if(safe->max_depth == 0 || safe->max_depth >= (p->depth + 1)) return;
96
100
 
97
- rb_raise(validation_error_class, "JSON is too deep!");
101
+ rb_raise(max_depth_error_class, "JSON is too deep!");
98
102
  }
99
103
 
100
104
  static void check_max_total_elements(safe_T safe) {
@@ -106,7 +110,7 @@ static void check_max_total_elements(safe_T safe) {
106
110
  */
107
111
  if(safe->max_total_elements == 0 || safe->max_total_elements > safe->current_elements_count) return;
108
112
 
109
- rb_raise(validation_error_class, "Too many elements!");
113
+ rb_raise(max_total_elements_error_class, "Too many elements!");
110
114
  }
111
115
 
112
116
  static void check_json_size(VALUE parser, VALUE json) {
@@ -119,7 +123,7 @@ static void check_json_size(VALUE parser, VALUE json) {
119
123
 
120
124
  if(safe->max_json_size_bytes == 0 || safe->max_json_size_bytes >= json_byte_size) return;
121
125
 
122
- rb_raise(validation_error_class, "JSON payload is too big!");
126
+ rb_raise(max_json_size_error_class, "JSON payload is too big!");
123
127
  }
124
128
 
125
129
  static void safe_start(ojParser p) {
@@ -440,8 +444,19 @@ static VALUE rb_safe_parse(VALUE self, VALUE json) {
440
444
  void Init_safe_ext(void) {
441
445
  VALUE oj_module = rb_const_get(rb_cObject, rb_intern("Oj"));
442
446
  VALUE safe_parser_class = rb_define_class_under(oj_module, "Safe", rb_cObject);
443
- validation_error_class = rb_define_class_under(safe_parser_class, "ValidationError", rb_eRuntimeError);
444
- rb_gc_register_address(&validation_error_class);
447
+ VALUE validation_error_class = rb_define_class_under(safe_parser_class, "ValidationError", rb_eRuntimeError);
448
+
449
+ max_hash_size_error_class = rb_define_class_under(safe_parser_class, "HashSizeError", validation_error_class);
450
+ max_array_size_error_class = rb_define_class_under(safe_parser_class, "ArraySizeError", validation_error_class);
451
+ max_depth_error_class = rb_define_class_under(safe_parser_class, "DepthError", validation_error_class);
452
+ max_total_elements_error_class = rb_define_class_under(safe_parser_class, "TotalElementsError", validation_error_class);
453
+ max_json_size_error_class = rb_define_class_under(safe_parser_class, "PayloadSizeError", validation_error_class);
454
+
455
+ rb_gc_register_address(&max_hash_size_error_class);
456
+ rb_gc_register_address(&max_array_size_error_class);
457
+ rb_gc_register_address(&max_depth_error_class);
458
+ rb_gc_register_address(&max_total_elements_error_class);
459
+ rb_gc_register_address(&max_json_size_error_class);
445
460
 
446
461
  max_hash_size_sym = ID2SYM(rb_intern("max_hash_size"));
447
462
  max_array_size_sym = ID2SYM(rb_intern("max_array_size"));
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Oj
4
4
  class Safe
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj-safe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Emin INAC