oj 3.0.8 → 3.0.9

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
  SHA1:
3
- metadata.gz: a944529c2d9fc9f12e3be88cb7edd568e3c32de9
4
- data.tar.gz: d40180c12d6ae9ee8e50fa13bbe49374674e5eb3
3
+ metadata.gz: 12393f7e80f652ce9474b8ef98704a943a3dbb7e
4
+ data.tar.gz: 97f4f982b38b117b27736018df3050ea40da2388
5
5
  SHA512:
6
- metadata.gz: a46eb91148fd3200c0226d38a7ad9bff977a037a0ebd93ddcda9b082f515e2561e815c01694c58ec17af7d9be9f83075a4f630c35b077c862b1de048173f1627
7
- data.tar.gz: af1bfff262e48d2f46282b5314247a98ea919fbb17f8b653fca03736f93944f61e1fba25b00df894020372ae0f3b1e3bddd2732c3be65dfe2c17bec6140d77e2
6
+ metadata.gz: 981d90bd2dd8bf6e6f1d5893d0bb25ba1429fe4399c9ea1b3574a6b2d137dc0be411c4a645fc387381e305e6e5b4daad9ae4e73b4aa896090ab79ceb790b9fd9
7
+ data.tar.gz: 4db2afa9967ce0a6ff2bd35392b377f156d06d5f4faea907ec750265f6f9ddb3336c8caf47165cfb3954290cea6629c890d58c5276149fb946b359f79987ceca
@@ -775,8 +775,8 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
775
775
  if (0x80 == (uint8_t)str[1] && (0xa8 == (uint8_t)str[2] || 0xa9 == (uint8_t)str[2])) {
776
776
  str = dump_unicode(str, end, out);
777
777
  } else {
778
+ check_start = check_unicode(str, end);
778
779
  *out->cur++ = *str;
779
- check_start = str + 3;
780
780
  }
781
781
  break;
782
782
  }
@@ -619,7 +619,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
619
619
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
620
620
 
621
621
  strcpy(buf, rb_string_value_ptr((VALUE*)&rstr));
622
- cnt = RSTRING_LEN(rstr);
622
+ cnt = (int)RSTRING_LEN(rstr);
623
623
  }
624
624
  assure_size(out, cnt);
625
625
  for (b = buf; '\0' != *b; b++) {
@@ -489,6 +489,7 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
489
489
  pi.options.create_ok = No;
490
490
  pi.options.allow_nan = (bang ? Yes : No);
491
491
  pi.options.nilnil = No;
492
+ pi.options.mode = CompatMode;
492
493
  pi.max_depth = 100;
493
494
 
494
495
  if (2 <= argc) {
@@ -550,7 +551,11 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
550
551
  }
551
552
  *args = *argv;
552
553
 
553
- return oj_pi_parse(1, args, &pi, 0, 0, 0);
554
+ if (T_STRING == rb_type(*args)) {
555
+ return oj_pi_parse(1, args, &pi, 0, 0, false);
556
+ } else {
557
+ return oj_pi_sparse(1, args, &pi, 0);
558
+ }
554
559
  }
555
560
 
556
561
  /* Document-method: parse
@@ -943,7 +943,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
943
943
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
944
944
 
945
945
  strcpy(buf, rb_string_value_ptr((VALUE*)&rstr));
946
- cnt = RSTRING_LEN(rstr);
946
+ cnt = (int)RSTRING_LEN(rstr);
947
947
  }
948
948
  }
949
949
  assure_size(out, cnt);
@@ -29,7 +29,7 @@ static int read_from_io_partial(Reader reader);
29
29
  //static int read_from_str(Reader reader);
30
30
 
31
31
  void
32
- oj_reader_init(Reader reader, VALUE io, int fd) {
32
+ oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
33
33
  VALUE io_class = rb_obj_class(io);
34
34
  VALUE stat;
35
35
  VALUE ftype;
@@ -76,7 +76,15 @@ oj_reader_init(Reader reader, VALUE io, int fd) {
76
76
  } else if (rb_respond_to(io, oj_read_id)) {
77
77
  reader->read_func = read_from_io;
78
78
  reader->io = io;
79
- } else {
79
+ } else if (to_s) {
80
+ volatile VALUE rstr = rb_funcall(io, oj_to_s_id, 0);
81
+
82
+ reader->read_func = 0;
83
+ reader->in_str = StringValuePtr(rstr);
84
+ reader->head = (char*)reader->in_str;
85
+ reader->tail = reader->head;
86
+ reader->read_end = reader->head + RSTRING_LEN(rstr);
87
+ } else {
80
88
  rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
81
89
  }
82
90
  }
@@ -26,7 +26,7 @@ typedef struct _Reader {
26
26
  };
27
27
  } *Reader;
28
28
 
29
- extern void oj_reader_init(Reader reader, VALUE io, int fd);
29
+ extern void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s);
30
30
  extern int oj_reader_read(Reader reader);
31
31
 
32
32
  static inline char
@@ -832,7 +832,7 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
832
832
  } else {
833
833
  pi->proc = Qundef;
834
834
  }
835
- oj_reader_init(&pi->rd, input, fd);
835
+ oj_reader_init(&pi->rd, input, fd, CompatMode == pi->options.mode);
836
836
  pi->json = 0; // indicates reader is in use
837
837
 
838
838
  if (Yes == pi->options.circular) {
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.0.8'
4
+ VERSION = '3.0.9'
5
5
  end
@@ -39,7 +39,7 @@ if a non-native type is encountered instead of raising an Exception.
39
39
  The `:compat` mode mimics the json gem. The json gem is built around the use
40
40
  of the `to_json(*)` method defined for a class. Oj attempts to provide the
41
41
  same functionality by being a drop in replacement with a few
42
- exceptions. [{file:JsonGem.md}](pages/JsonGem.md) includes more details on
42
+ exceptions. [{file:JsonGem.md}](JsonGem.md) includes more details on
43
43
  compatibility and use.
44
44
 
45
45
  ## :rails Mode
@@ -47,7 +47,7 @@ compatibility and use.
47
47
  The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
48
48
  ActiveSupport are built around the use of the `as_json(*)` method defined for
49
49
  a class. Oj attempts to provide the same functionality by being a drop in
50
- replacement with a few exceptions. [{file:Rails.md}](pages/Rails.md) includes
50
+ replacement with a few exceptions. [{file:Rails.md}](Rails.md) includes
51
51
  more details on compatibility and use.
52
52
 
53
53
  ## :object Mode
@@ -58,7 +58,7 @@ default mode unless changed in the Oj default options. In :object mode Oj
58
58
  generates JSON that follows conventions which allow Class and other
59
59
  information such as Object IDs for circular reference detection to be encoded
60
60
  in a JSON document. The formatting follows the rules describe on the
61
- [{file:Encoding.md}](pages/Encoding.md) page.
61
+ [{file:Encoding.md}](Encoding.md) page.
62
62
 
63
63
  ## :custom Mode
64
64
 
@@ -68,7 +68,7 @@ some special aspect that makes it unique. For example, the `:object` mode has
68
68
  it's own unique format for object dumping and loading. The `:compat` mode
69
69
  mimic the json gem including methods called for encoding and inconsistencies
70
70
  between `JSON.dump()`, `JSON.generate()`, and `JSON()`. More details on the
71
- [{file:Custom.md}](pages/Custom.md) page.
71
+ [{file:Custom.md}](Custom.md) page.
72
72
 
73
73
  ## Options Matrix
74
74
 
@@ -47,6 +47,15 @@ class CompatJuice < Minitest::Test
47
47
  end
48
48
  end # Argy
49
49
 
50
+ class Stringy
51
+ def initialize()
52
+ end
53
+
54
+ def to_s()
55
+ %|[1,2]|
56
+ end
57
+ end # Stringy
58
+
50
59
  module One
51
60
  module Two
52
61
  module Three
@@ -275,12 +284,7 @@ class CompatJuice < Minitest::Test
275
284
  end
276
285
 
277
286
  def test_infinity
278
- begin
279
- Oj.load('Infinity', :mode => :strict)
280
- fail()
281
- rescue Oj::ParseError
282
- assert(true)
283
- end
287
+ assert_raises(Oj::ParseError) { Oj.load('Infinity', :mode => :strict) }
284
288
  x = Oj.load('Infinity', :mode => :compat)
285
289
  assert_equal('Infinity', x.to_s)
286
290
  end
@@ -461,21 +465,20 @@ class CompatJuice < Minitest::Test
461
465
  end
462
466
 
463
467
  def test_bad_unicode
464
- begin
465
- Oj.to_json("\xE4xy")
466
- fail()
467
- rescue Exception
468
- assert(true)
469
- end
468
+ assert_raises() { Oj.to_json("\xE4xy") }
469
+ end
470
+
471
+ def test_bad_unicode_e2
472
+ assert_raises() { Oj.to_json("L\xE2m ") }
470
473
  end
471
474
 
472
475
  def test_bad_unicode_start
473
- begin
474
- Oj.to_json("\x8abc")
475
- fail()
476
- rescue Exception
477
- assert(true)
478
- end
476
+ assert_raises() { Oj.to_json("\x8abc") }
477
+ end
478
+
479
+ def test_parse_to_s
480
+ s = Stringy.new
481
+ assert_equal([1,2], Oj.load(s, :mode => :compat))
479
482
  end
480
483
 
481
484
  def dump_and_load(obj, trace=false)
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.0.8
4
+ version: 3.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler