oj 3.6.12 → 3.6.13

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: 3517ed09e956844a399f8986027f8990949bb7702c9e88a5b4fa4f2fc9d4eb07
4
- data.tar.gz: 16292809c8dced3cfd7dd6cfb110d85c88256d74c08586e4c436f92cab8888dc
3
+ metadata.gz: 1f5fd9fac91126f270714362850b976b7f4cf1102462aab26c2f4f65f457a905
4
+ data.tar.gz: e2e200e2ec9e76f073206c084c1a7e45592710e0fbb43a5ba4f9593af74ff583
5
5
  SHA512:
6
- metadata.gz: bc24329317395830e448ec06373ff27458c33612ce6fec0b4a79515c63f43164afb82a093cdbae7a6d6244885f2df16da0fba449c63b283af814769b4ed78147
7
- data.tar.gz: 10ff64b0f48d1962c26f213e92456de839b65ab595c2925890a1eabd590160be355674bde197e0d65f4de4e1c9d246c1ce1c12f1adedc3c2aca967b3fd339390
6
+ metadata.gz: 3b5f0e4bede1f60d010a51e32141c6b864f92abe17fbe12d310e805ce16b8ef67483cf51dee0914f6a29f54556817d91ed2ffa5dccb64cbd8468c68de0d50f83
7
+ data.tar.gz: 390a4c2953392485757949aee885fb82b3c54b456f659ba672ae7b8da0b45bee484eb3b7c3ee0ef31a01dd33fe0bac8e877d01c91649c197970defe3e7727399
@@ -230,12 +230,37 @@ dump_hex(uint8_t c, Out out) {
230
230
  *out->cur++ = hex_chars[d];
231
231
  }
232
232
 
233
+ static void
234
+ raise_invalid_unicode(const char *str, int len, int pos) {
235
+ char buf[len + 1];
236
+ char c;
237
+ char code[32];
238
+ char *cp = code;
239
+ int i;
240
+ uint8_t d;
241
+
242
+ *cp++ = '[';
243
+ for (i = pos; i < len && i - pos < 5; i++) {
244
+ c = str[i];
245
+ d = (c >> 4) & 0x0F;
246
+ *cp++ = hex_chars[d];
247
+ d = c & 0x0F;
248
+ *cp++ = hex_chars[d];
249
+ *cp++ = ' ';
250
+ }
251
+ cp--;
252
+ *cp++ = ']';
253
+ *cp = '\0';
254
+ strncpy(buf, str, len);
255
+ rb_raise(oj_json_generator_error_class, "Invalid Unicode %s at %d in '%s'", code, pos, buf);
256
+ }
257
+
233
258
  static const char*
234
- dump_unicode(const char *str, const char *end, Out out) {
259
+ dump_unicode(const char *str, const char *end, Out out, const char *orig) {
235
260
  uint32_t code = 0;
236
261
  uint8_t b = *(uint8_t*)str;
237
262
  int i, cnt;
238
-
263
+
239
264
  if (0xC0 == (0xE0 & b)) {
240
265
  cnt = 1;
241
266
  code = b & 0x0000001F;
@@ -253,13 +278,13 @@ dump_unicode(const char *str, const char *end, Out out) {
253
278
  code = b & 0x00000001;
254
279
  } else {
255
280
  cnt = 0;
256
- rb_raise(oj_json_generator_error_class, "Invalid Unicode");
281
+ raise_invalid_unicode(orig, (int)(end - orig), (int)(str - orig));
257
282
  }
258
283
  str++;
259
284
  for (; 0 < cnt; cnt--, str++) {
260
285
  b = *(uint8_t*)str;
261
286
  if (end <= str || 0x80 != (0xC0 & b)) {
262
- rb_raise(oj_json_generator_error_class, "Invalid Unicode");
287
+ raise_invalid_unicode(orig, (int)(end - orig), (int)(str - orig));
263
288
  }
264
289
  code = (code << 6) | (b & 0x0000003F);
265
290
  }
@@ -284,7 +309,7 @@ dump_unicode(const char *str, const char *end, Out out) {
284
309
  }
285
310
 
286
311
  static const char*
287
- check_unicode(const char *str, const char *end) {
312
+ check_unicode(const char *str, const char *end, const char *orig) {
288
313
  uint8_t b = *(uint8_t*)str;
289
314
  int cnt;
290
315
 
@@ -299,13 +324,13 @@ check_unicode(const char *str, const char *end) {
299
324
  } else if (0xFC == (0xFE & b)) {
300
325
  cnt = 5;
301
326
  } else {
302
- rb_raise(oj_json_generator_error_class, "Invalid Unicode");
327
+ raise_invalid_unicode(orig, (int)(end - orig), (int)(str - orig));
303
328
  }
304
329
  str++;
305
330
  for (; 0 < cnt; cnt--, str++) {
306
331
  b = *(uint8_t*)str;
307
332
  if (end <= str || 0x80 != (0xC0 & b)) {
308
- rb_raise(oj_json_generator_error_class, "Invalid Unicode");
333
+ raise_invalid_unicode(orig, (int)(end - orig), (int)(str - orig));
309
334
  }
310
335
  }
311
336
  return str;
@@ -783,9 +808,9 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
783
808
  if (JXEsc == out->opts->escape_mode && check_start <= str) {
784
809
  if (0 != (0x80 & (uint8_t)*str)) {
785
810
  if (0xC0 == (0xC0 & (uint8_t)*str)) {
786
- check_start = check_unicode(str, end);
811
+ check_start = check_unicode(str, end, orig);
787
812
  } else {
788
- rb_raise(oj_json_generator_error_class, "Invalid Unicode");
813
+ raise_invalid_unicode(orig, (int)(end - orig), (int)(str - orig));
789
814
  }
790
815
  }
791
816
  }
@@ -806,14 +831,14 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
806
831
  case '3': // Unicode
807
832
  if (0xe2 == (uint8_t)*str && JXEsc == out->opts->escape_mode && 2 <= end - str) {
808
833
  if (0x80 == (uint8_t)str[1] && (0xa8 == (uint8_t)str[2] || 0xa9 == (uint8_t)str[2])) {
809
- str = dump_unicode(str, end, out);
834
+ str = dump_unicode(str, end, out, orig);
810
835
  } else {
811
- check_start = check_unicode(str, end);
836
+ check_start = check_unicode(str, end, orig);
812
837
  *out->cur++ = *str;
813
838
  }
814
839
  break;
815
840
  }
816
- str = dump_unicode(str, end, out);
841
+ str = dump_unicode(str, end, out, orig);
817
842
  break;
818
843
  case '6': // control characters
819
844
  if (*(uint8_t*)str < 0x80) {
@@ -825,14 +850,14 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
825
850
  } else {
826
851
  if (0xe2 == (uint8_t)*str && JXEsc == out->opts->escape_mode && 2 <= end - str) {
827
852
  if (0x80 == (uint8_t)str[1] && (0xa8 == (uint8_t)str[2] || 0xa9 == (uint8_t)str[2])) {
828
- str = dump_unicode(str, end, out);
853
+ str = dump_unicode(str, end, out, orig);
829
854
  } else {
830
- check_start = check_unicode(str, end);
855
+ check_start = check_unicode(str, end, orig);
831
856
  *out->cur++ = *str;
832
857
  }
833
858
  break;
834
859
  }
835
- str = dump_unicode(str, end, out);
860
+ str = dump_unicode(str, end, out, orig);
836
861
  }
837
862
  break;
838
863
  default:
@@ -971,7 +971,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
971
971
  if (0 != line) {
972
972
  VALUE ec = rb_obj_class(rb_errinfo());
973
973
 
974
- if (rb_eArgError != ec) {
974
+ if (rb_eArgError != ec && 0 != ec) {
975
975
  err_class = ec;
976
976
  }
977
977
  }
@@ -1008,6 +1008,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
1008
1008
  oj_rxclass_cleanup(&pi->str_rx);
1009
1009
  }
1010
1010
  if (err_has(&pi->err)) {
1011
+ rb_set_errinfo(Qnil);
1011
1012
  if (Qnil != pi->err_class) {
1012
1013
  pi->err.clas = pi->err_class;
1013
1014
  }
@@ -844,7 +844,8 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
844
844
  if (0 != line) {
845
845
  VALUE ec = rb_obj_class(rb_errinfo());
846
846
 
847
- if (rb_eArgError != ec) {
847
+ // Sometimes the claass of the error is 0 which seems broken.
848
+ if (rb_eArgError != ec && 0 != ec) {
848
849
  err_class = ec;
849
850
  }
850
851
  }
@@ -876,7 +877,8 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
876
877
  close(fd);
877
878
  }
878
879
  if (err_has(&pi->err)) {
879
- if (Qnil != pi->err_class) {
880
+ rb_set_errinfo(Qnil);
881
+ if (Qnil != pi->err_class && 0 != pi->err_class) {
880
882
  pi->err.clas = pi->err_class;
881
883
  }
882
884
  if (CompatMode == pi->options.mode) {
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.6.12'
4
+ VERSION = '3.6.13'
5
5
  end
@@ -6,12 +6,65 @@ $: << '../ext'
6
6
 
7
7
  require 'oj'
8
8
 
9
- 10.times {
10
- io = StringIO.new
11
- w = Oj::StreamWriter.new(io)
12
- w.push_array
13
- child = {"id"=>"1", "name"=>"foo", "nilElement"=>nil}
14
- w.push_value(child)
15
- puts io.string
16
- }
9
+ #Oj.load(StringIO.new(Oj.dump({ records: 1.upto(25).map{|i| { id: i, name: "record_#{i}" }} }, mode: :strict)))
10
+
11
+ class MyParser
12
+ attr_accessor :enum
13
+
14
+ def initialize
15
+ @io = StringIO.new
16
+ @writer = Oj::StreamWriter.new(@io)
17
+
18
+ json_string = Oj.dump({ records: 1.upto(25).map{|i| { id: i, name: "record_#{i}" }} }, mode: :strict)
19
+ @test_json = StringIO.new(json_string)
20
+
21
+ @enum = Enumerator.new do |yielder|
22
+ @yielder = yielder
23
+ Oj.sc_parse(self, @test_json)
24
+ end
25
+ end
26
+
27
+ # Stream parsing methods
28
+ def hash_start
29
+ @writer.push_object
30
+ end
31
+
32
+ def hash_end
33
+ @writer.pop unless @io.eof
34
+ end
35
+
36
+ def hash_key(key)
37
+ @writer.push_key(key)
38
+ end
39
+
40
+ def hash_set(h, key, value)
41
+ @writer.push_value(value)
42
+ end
43
+
44
+ def array_start
45
+ @writer.push_array
46
+ end
47
+
48
+ def array_end
49
+ @writer.pop
50
+ end
51
+
52
+ def array_append(a, value)
53
+ yield_data
54
+ end
55
+
56
+ def add_value(value);end
57
+
58
+ def yield_data
59
+ @writer.pop_all
60
+ @yielder << @io.string
61
+ @io.reopen("")
62
+ array_start
63
+ end
64
+ end
65
+
66
+ MyParser.new.enum.each.with_index do |r, i|
67
+ break if i == 0
68
+ end
69
+
17
70
 
@@ -393,6 +393,12 @@ class Juice < Minitest::Test
393
393
  out = Oj.dump(x)
394
394
  assert_equal(json, out)
395
395
  end
396
+ def test_dump_invalid_utf8
397
+ Oj.default_options = { :escape_mode => :ascii }
398
+ assert_raises(EncodingError) {
399
+ Oj.dump(["abc\xbe\x1f\x11"], mode: :strict)
400
+ }
401
+ end
396
402
 
397
403
  # Symbol
398
404
  def test_symbol_null
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.12
4
+ version: 3.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-16 00:00:00.000000000 Z
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  version: '0'
272
272
  requirements: []
273
273
  rubyforge_project:
274
- rubygems_version: 2.7.6
274
+ rubygems_version: 2.7.7
275
275
  signing_key:
276
276
  specification_version: 4
277
277
  summary: A fast JSON parser and serializer.