oj 2.9.5 → 2.9.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e14bd3bc917698abb03e0a65db6ad92ebc89cb38
4
- data.tar.gz: 1290ce177f66c2dffb8dd852b03faab17bab15ec
3
+ metadata.gz: aa935c82f850cb8bacad4b1dfdbeebdfd0af777f
4
+ data.tar.gz: 1bf95c9767bb1ee814871a859fd2312fbe00dd28
5
5
  SHA512:
6
- metadata.gz: 92b820c57e3c81d2fb716d9726476fb28dd13384436910caec2d930f2464249066d4a9326e519c76dc8aeba7194bfa12e5d00acd69a8aadf81d85ada921b949c
7
- data.tar.gz: 126a7c2f3ebc4c660894df4d75f723e9180e7fd38c1e25ec56b79d29f10299eab2b40a81ee8899fe496eaee91754d09d96b41c6f81eae422729c3c5b6f579f2c
6
+ metadata.gz: 10e76efb7219459edcc77fec2518dc1c9e036cfa7a2f7c3d49942b3b26085d3b45a25fae451c934eadc087656abc7d2678813de3be7496e5665bb9f7c6278d05
7
+ data.tar.gz: 4643da9813d1664bbbf06bd6ca7a29e3a9c5fac54d0750ac0fc05e25ea6c72cbab825eaf5901cd029eccff9f00eeb7e3d6fcc3c761a37793452f85b81685540e
data/README.md CHANGED
@@ -26,21 +26,12 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
26
26
 
27
27
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
28
 
29
- ### Current Release 2.9.5
29
+ ### Current Release 2.9.6
30
30
 
31
- - Mimic mode now monkey patches Object like JSON.
31
+ - Fixed bug using StringIO with SCParser.
32
32
 
33
- - A big thanks to krasnoukhov for reorganizing test and helping get Oj more
34
- rails compatible.
35
-
36
- - Another thanks goes out to lautis for a pull request that provided some
37
- optimization and fixed the return exception for an embedded null in a string.
38
-
39
- - Fixed a bug with zip reader streams where EOF was not handled nicely.
40
-
41
- ### Current Release 2.9.4
42
-
43
- - In mimic mode parse errors now match the JSON::ParserError.
33
+ - Tightened up JSON mimic to raise an exception if JSON.parse is called on
34
+ a JSON documents that returns a primitive type.
44
35
 
45
36
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
46
37
 
@@ -1614,6 +1614,7 @@ static VALUE
1614
1614
  mimic_parse(int argc, VALUE *argv, VALUE self) {
1615
1615
  struct _ParseInfo pi;
1616
1616
  VALUE args[1];
1617
+ VALUE result;
1617
1618
 
1618
1619
  if (argc < 1) {
1619
1620
  rb_raise(rb_eArgError, "Wrong number of arguments to parse.");
@@ -1643,7 +1644,22 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
1643
1644
  }
1644
1645
  *args = *argv;
1645
1646
 
1646
- return oj_pi_parse(1, args, &pi, 0, 0, 0);
1647
+ result = oj_pi_parse(1, args, &pi, 0, 0, 0);
1648
+ switch (rb_type(result)) {
1649
+ case T_NIL:
1650
+ case T_TRUE:
1651
+ case T_FALSE:
1652
+ case T_FIXNUM:
1653
+ case T_FLOAT:
1654
+ case T_CLASS:
1655
+ case T_SYMBOL:
1656
+ rb_raise(oj_parse_error_class, "parse is only allowed to return data structure.");
1657
+ break;
1658
+ default:
1659
+ // okay
1660
+ break;
1661
+ }
1662
+ return result;
1647
1663
  }
1648
1664
 
1649
1665
  static VALUE
@@ -265,7 +265,7 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
265
265
  #endif
266
266
  if (oj_stringio_class == clas) {
267
267
  s = rb_funcall2(input, oj_string_id, 0, 0);
268
- oj_pi_set_input_str(&pi, input);
268
+ oj_pi_set_input_str(&pi, s);
269
269
  #if !IS_WINDOWS
270
270
  // JRuby gets confused with what is the real fileno.
271
271
  } else if (rb_respond_to(input, oj_fileno_id) &&
@@ -30,10 +30,56 @@ module Oj
30
30
  #
31
31
  # def hash_start(); end
32
32
  # def hash_end(); end
33
+ # def hash_set(h, key, value); end
33
34
  # def array_start(); end
34
35
  # def array_end(); end
36
+ # def array_append(a, value); end
35
37
  # def add_value(value); end
36
- # def error(message, line, column); end
38
+ #
39
+ # As certain elements of a JSON document are reached during parsing the
40
+ # callbacks are called. The parser helps by keeping track of objects created
41
+ # by the callbacks but does not create those objects itself.
42
+ #
43
+ # hash_start
44
+ #
45
+ # When a JSON object element starts the hash_start() callback is called if
46
+ # public. It should return what ever Ruby Object is to be used as the element
47
+ # that will later be included in the hash_set() callback.
48
+ #
49
+ # hash_end
50
+ #
51
+ # At the end of a JSON object element the hash_end() callback is called if public.
52
+ #
53
+ # hash_set
54
+ #
55
+ # When a key value pair is encountered during parsing the hash_set() callback
56
+ # is called if public. The first element will be the object returned from the
57
+ # enclosing hash_start() callback. The second argument is the key and the last
58
+ # is the value.
59
+ #
60
+ # array_start
61
+ #
62
+ # When a JSON array element is started the array_start() callback is called if
63
+ # public. It should return what ever Ruby Object is to be used as the element
64
+ # that will later be included in the array_append() callback.
65
+ #
66
+ # array_end
67
+ #
68
+ # At the end of a JSON array element the array_end() callback is called if public.
69
+ #
70
+ # array_append
71
+ #
72
+ # When a element is encountered that is an element of an array the
73
+ # array_append() callback is called if public. The first argument to the
74
+ # callback is the Ruby object returned from the enclosing array_start()
75
+ # callback.
76
+ #
77
+ # add_value
78
+ #
79
+ # The handler is expected to handle multiple JSON elements in one stream,
80
+ # file, or string. When a top level JSON has been read completely the
81
+ # add_value() callback is called. Even if only one element was ready this
82
+ # callback returns the Ruby object that was constructed during the parsing.
37
83
  #
38
84
  class ScHandler
39
85
  # Create a new instance of the ScHandler class.
@@ -51,6 +97,9 @@ module Oj
51
97
  def hash_end()
52
98
  end
53
99
 
100
+ def hash_set(h, key, value)
101
+ end
102
+
54
103
  def array_start()
55
104
  end
56
105
 
@@ -60,11 +109,8 @@ module Oj
60
109
  def add_value(value)
61
110
  end
62
111
 
63
- def hash_set(h, key, value)
64
- end
65
-
66
112
  def array_append(a, value)
67
113
  end
68
-
114
+
69
115
  end # ScHandler
70
116
  end # Oj
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.9.5'
4
+ VERSION = '2.9.6'
5
5
  end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #!/usr/bin/env ruby
4
+ # encoding: UTF-8
5
+
6
+ $: << File.dirname(__FILE__)
7
+
8
+ require 'helper'
9
+
10
+ File.open('tst', 'r') do |file|
11
+ puts file.gets
12
+ puts file.read(1)
13
+ Oj.load(file) do |val|
14
+ puts "*** inside: #{val}"
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ class Handler
9
+ def initialize
10
+ @state = []
11
+ end
12
+
13
+ def hash_start
14
+ @state << {}
15
+ @state.last
16
+ end
17
+
18
+ def hash_end
19
+ @state.pop
20
+ end
21
+
22
+ def hash_set(h,k,v)
23
+ h.store(k,v)
24
+ end
25
+
26
+ def array_start
27
+ @state << []
28
+ @state.last
29
+ end
30
+
31
+
32
+ def array_end
33
+ @state.pop
34
+ end
35
+
36
+ def array_append(a,v)
37
+ a << v
38
+ end
39
+
40
+ def error(message, line, column); p "ERROR: #{message}" end
41
+ end
42
+
43
+ handler = Handler.new
44
+ def handler.add_value(v)
45
+ p v
46
+ end
47
+
48
+ Oj.sc_parse(handler, StringIO.new('{"a":"b","c":[1,2,{"d":"e"}]}[4,5,6]'))
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: 2.9.5
4
+ version: 2.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-07 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -102,8 +102,10 @@ files:
102
102
  - lib/oj/schandler.rb
103
103
  - lib/oj/version.rb
104
104
  - test/_test_mimic_rails.rb
105
+ - test/bug.rb
105
106
  - test/files.rb
106
107
  - test/helper.rb
108
+ - test/io.rb
107
109
  - test/isolated/shared.rb
108
110
  - test/isolated/test_mimic_after.rb
109
111
  - test/isolated/test_mimic_alone.rb
@@ -176,3 +178,4 @@ signing_key:
176
178
  specification_version: 4
177
179
  summary: A fast JSON parser and serializer.
178
180
  test_files: []
181
+ has_rdoc: true