oj 3.6.10 → 3.6.11

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: 8a87c62472d113e29856309232619790b751b188625b5f8500188f3d33225ceb
4
- data.tar.gz: aaa3439fab55eb25f6ea54a4dc200dc0a97df79a5d0e1b8a1cd5b2a04550b8f7
3
+ metadata.gz: cef33c35dc056f48604161c781e420fcd13b54e2f674aa3f9722e1c8bc25cfc2
4
+ data.tar.gz: 96425922ddda704b173f52fae3c897f1574b373784bf5cb5be18d8223f03bef0
5
5
  SHA512:
6
- metadata.gz: f3dbefcb405bb2283b099206a5916970f4a06afc69354a1a3a3330ee45b1c0d4c6a9799626775131e85ca3a3b8ac93ff2663cddc81253f00a611d0e562626833
7
- data.tar.gz: 2c4fb14af2b3840c69695998091ad25163ad3325e42d777c1a133ed427fac22ec096e2ed9d235f0814f0c8c2de5bfff823d0e12d1f2081ef66dfd74acb49d6b9
6
+ metadata.gz: b18e9dbf9b3fb6082210470e560384b1fe5547e35e615fc8717c23342d003ce2923de22d263ae37e708c080ba0d92f75d3be374d7197a49ec79ab619e677cdbe
7
+ data.tar.gz: bb9c2884eff2f1e841b6a31339b2e19f92680309ea7042bb7b44bb6a31a4ba5f963106099ce2bb58e9705ec25d60dbe82149c009b830133e6569aa78745bfd3a
@@ -796,12 +796,42 @@ oj_num_as_value(NumInfo ni) {
796
796
  void
797
797
  oj_set_error_at(ParseInfo pi, VALUE err_clas, const char* file, int line, const char *format, ...) {
798
798
  va_list ap;
799
- char msg[128];
799
+ char msg[256];
800
+ char *p = msg;
801
+ char *end = p + sizeof(msg) - 2;
802
+ char *start;
803
+ Val vp;
800
804
 
801
805
  va_start(ap, format);
802
- vsnprintf(msg, sizeof(msg) - 1, format, ap);
806
+ p += vsnprintf(msg, sizeof(msg) - 1, format, ap);
803
807
  va_end(ap);
804
808
  pi->err.clas = err_clas;
809
+ if (p + 3 < end) {
810
+ *p++ = ' ';
811
+ *p++ = '(';
812
+ start = p;
813
+ for (vp = pi->stack.head; vp < pi->stack.tail; vp++) {
814
+ if (end <= p + 1 + vp->klen) {
815
+ break;
816
+ }
817
+ if (NULL != vp->key) {
818
+ if (start < p) {
819
+ *p++ = '.';
820
+ }
821
+ memcpy(p, vp->key, vp->klen);
822
+ p += vp->klen;
823
+ } else {
824
+ if (RUBY_T_ARRAY == rb_type(vp->val)) {
825
+ if (end <= p + 12) {
826
+ break;
827
+ }
828
+ p += snprintf(p, end - p, "[%ld]", RARRAY_LEN(vp->val));
829
+ }
830
+ }
831
+ }
832
+ *p++ = ')';
833
+ }
834
+ *p = '\0';
805
835
  if (0 == pi->json) {
806
836
  oj_err_set(&pi->err, err_clas, "%s at line %d, column %d [%s:%d]", msg, pi->rd.line, pi->rd.col, file, line);
807
837
  } else {
@@ -936,23 +966,31 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
936
966
  if (!err_has(&pi->err)) {
937
967
  // If the stack is not empty then the JSON terminated early.
938
968
  Val v;
969
+ VALUE err_class = oj_parse_error_class;
970
+
971
+ if (0 != line) {
972
+ VALUE ec = rb_obj_class(rb_errinfo());
939
973
 
940
- if (0 != (v = stack_peek(&pi->stack))) {
974
+ if (rb_eArgError != ec) {
975
+ err_class = ec;
976
+ }
977
+ }
978
+ if (NULL != (v = stack_peek(&pi->stack))) {
941
979
  switch (v->next) {
942
980
  case NEXT_ARRAY_NEW:
943
981
  case NEXT_ARRAY_ELEMENT:
944
982
  case NEXT_ARRAY_COMMA:
945
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Array not terminated");
983
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated");
946
984
  break;
947
985
  case NEXT_HASH_NEW:
948
986
  case NEXT_HASH_KEY:
949
987
  case NEXT_HASH_COLON:
950
988
  case NEXT_HASH_VALUE:
951
989
  case NEXT_HASH_COMMA:
952
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Hash/Object not terminated");
990
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Hash/Object not terminated");
953
991
  break;
954
992
  default:
955
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not terminated");
993
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "not terminated");
956
994
  }
957
995
  }
958
996
  }
@@ -969,9 +1007,6 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
969
1007
  if (pi->str_rx.head != oj_default_options.str_rx.head) {
970
1008
  oj_rxclass_cleanup(&pi->str_rx);
971
1009
  }
972
- if (0 != line) {
973
- rb_jump_tag(line);
974
- }
975
1010
  if (err_has(&pi->err)) {
976
1011
  if (Qnil != pi->err_class) {
977
1012
  pi->err.clas = pi->err_class;
@@ -992,6 +1027,8 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
992
1027
  } else {
993
1028
  oj_err_raise(&pi->err);
994
1029
  }
1030
+ } else if (0 != line) {
1031
+ rb_jump_tag(line);
995
1032
  }
996
1033
  if (pi->options.quirks_mode == No) {
997
1034
  switch (rb_type(result)) {
@@ -839,23 +839,31 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
839
839
  if (!err_has(&pi->err)) {
840
840
  // If the stack is not empty then the JSON terminated early.
841
841
  Val v;
842
+ VALUE err_class = oj_parse_error_class;
842
843
 
844
+ if (0 != line) {
845
+ VALUE ec = rb_obj_class(rb_errinfo());
846
+
847
+ if (rb_eArgError != ec) {
848
+ err_class = ec;
849
+ }
850
+ }
843
851
  if (0 != (v = stack_peek(&pi->stack))) {
844
852
  switch (v->next) {
845
853
  case NEXT_ARRAY_NEW:
846
854
  case NEXT_ARRAY_ELEMENT:
847
855
  case NEXT_ARRAY_COMMA:
848
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Array not terminated");
856
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated");
849
857
  break;
850
858
  case NEXT_HASH_NEW:
851
859
  case NEXT_HASH_KEY:
852
860
  case NEXT_HASH_COLON:
853
861
  case NEXT_HASH_VALUE:
854
862
  case NEXT_HASH_COMMA:
855
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Hash/Object not terminated");
863
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Hash/Object not terminated");
856
864
  break;
857
865
  default:
858
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not terminated");
866
+ oj_set_error_at(pi, err_class, __FILE__, __LINE__, "not terminated");
859
867
  }
860
868
  }
861
869
  }
@@ -867,9 +875,6 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
867
875
  if (0 != fd) {
868
876
  close(fd);
869
877
  }
870
- if (0 != line) {
871
- rb_jump_tag(line);
872
- }
873
878
  if (err_has(&pi->err)) {
874
879
  if (Qnil != pi->err_class) {
875
880
  pi->err.clas = pi->err_class;
@@ -886,8 +891,9 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
886
891
  } else {
887
892
  oj_err_raise(&pi->err);
888
893
  }
889
-
890
894
  oj_err_raise(&pi->err);
895
+ } else if (0 != line) {
896
+ rb_jump_tag(line);
891
897
  }
892
898
  return result;
893
899
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.6.10'
4
+ VERSION = '3.6.11'
5
5
  end
@@ -346,6 +346,16 @@ class ScpTest < Minitest::Test
346
346
  end
347
347
  end
348
348
 
349
+ def test_bad_bignum
350
+ if '2.4.0' < RUBY_VERSION
351
+ handler = AllHandler.new()
352
+ json = %|{"big":-e123456789}|
353
+ assert_raises Oj::ParseError do
354
+ Oj.sc_parse(handler, json)
355
+ end
356
+ end
357
+ end
358
+
349
359
  def test_pipe_close
350
360
  # Windows does not support fork
351
361
  return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
@@ -29,7 +29,7 @@ class Juice < Minitest::Test
29
29
  end
30
30
  alias == eql?
31
31
 
32
- end# Jam
32
+ end # Jam
33
33
 
34
34
  class Jeez < Jam
35
35
  def initialize(x, y)
@@ -43,7 +43,7 @@ class Juice < Minitest::Test
43
43
  def self.json_create(h)
44
44
  self.new(h['x'], h['y'])
45
45
  end
46
- end# Jeez
46
+ end # Jeez
47
47
 
48
48
  # contributed by sauliusg to fix as_json
49
49
  class Orange < Jam
@@ -86,7 +86,7 @@ class Juice < Minitest::Test
86
86
  def self.json_create(h)
87
87
  self.new(h['x'], h['y'])
88
88
  end
89
- end# Jazz
89
+ end # Jazz
90
90
 
91
91
  def setup
92
92
  @default_options = Oj.default_options
@@ -661,6 +661,29 @@ class Juice < Minitest::Test
661
661
  assert_equal('string', Oj.load('"string"', :quirks_mode => true))
662
662
  end
663
663
 
664
+ def test_error_path
665
+ msg = ''
666
+ assert_raises(Oj::ParseError) {
667
+ begin
668
+ Oj.load(%|{
669
+ "first": [
670
+ 1, 2, { "third": 123x }
671
+ ]
672
+ }|)
673
+ rescue Oj::ParseError => e
674
+ msg = e.message
675
+ raise e
676
+ end
677
+ }
678
+ assert_equal('first[2].third', msg.split('(')[1].split(')')[0])
679
+ end
680
+
681
+ def test_bad_bignum
682
+ if '2.4.0' < RUBY_VERSION
683
+ assert_raises(Oj::ParseError) { Oj.load(%|{ "big": -e123456789 }|) }
684
+ end
685
+ end
686
+
664
687
  def test_quirks_array_mode
665
688
  assert_equal([], Oj.load("[]", :quirks_mode => false))
666
689
  assert_equal([], Oj.load("[]", :quirks_mode => true))
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.10
4
+ version: 3.6.11
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-09-13 00:00:00.000000000 Z
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler