oj 2.0.13 → 2.0.14

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: 668ead8e90334db6467d560eea8f2bb1f514fc53
4
- data.tar.gz: 2556e815c19eaf4b0a2cdd432a25942420166cfe
3
+ metadata.gz: 4f45b0b28345f47bc50144ccd5750143f5a3ccb0
4
+ data.tar.gz: ba321d9b7543648e1b024f85a2b1257b876c414b
5
5
  SHA512:
6
- metadata.gz: 63163bdb7c6b7b1580072f33c8256126cf087313cd3f85ba3cb899431ce139a81ee24eafbc11fa362e1611b02ecaadb6bf58bf2cc1d2a1c55aebbbd6341d0535
7
- data.tar.gz: 3fee65bcd045885bed8e744ea4f51cb6bb93c14220c2de5ef272d624aa03aa1949f3afca1da02ad10102396052cb5a898020d338e9064916dccc94a140dc3231
6
+ metadata.gz: 9a290c251d3bfd068add15c3f7238807efb7ea7d6321161008e11000a9492cfbb52731e18b7c29bfca57e97540d5158bc08cbacbfa1cd680c8d190bf2c6b8152
7
+ data.tar.gz: b6bdfc9702edf98b18487ddea0aa5ee9502baac7dd286f7aa7033456de40cc870714920244877690b7390220a611e86b528b0fea243c31a8c8064cfc958ac942
data/README.md CHANGED
@@ -32,16 +32,13 @@ A fast JSON parser and Object marshaller as a Ruby gem.
32
32
 
33
33
  ## <a name="release">Release Notes</a>
34
34
 
35
- ### Release 2.0.13
35
+ ### Release 2.0.14
36
36
 
37
- - Mimic is better at masking out json gem but the oj_mimic_json gem does not
38
- work with ruby 2.0.0 correctly. The Oj.mimic_JSON() method should be called
39
- directly either before or after the json gem is required. Depending on the
40
- situation one may work better than the other. Oj.mimic_JSON() may now be
41
- called multiple times.
37
+ - Fixed bug in Oj::Doc.each_leaf that caused an incorrect where path to be
38
+ created and also added a chack for where path maximum length.
42
39
 
43
- - Changed dump to put closing array brackets and closing object curlies on the
44
- line following the last element if :indent is set to greater than zero.
40
+ - Updated the documentation to note that invalid JSON documents, which includes
41
+ an empty string or file, will cause an exception to be raised.
45
42
 
46
43
  ## <a name="description">Description</a>
47
44
 
@@ -902,6 +902,9 @@ get_doc_leaf(Doc doc, const char *path) {
902
902
  } else {
903
903
  size_t cnt = doc->where - doc->where_path;
904
904
 
905
+ if (MAX_STACK <= cnt) {
906
+ rb_raise(rb_const_get_at(Oj, rb_intern("DepthError")), "Path too deep. Limit is %d levels.", MAX_STACK);
907
+ }
905
908
  memcpy(stack, doc->where_path, sizeof(Leaf) * cnt);
906
909
  lp = stack + cnt;
907
910
  }
@@ -988,11 +991,15 @@ each_leaf(Doc doc, VALUE self) {
988
991
  Leaf e = first;
989
992
 
990
993
  doc->where++;
994
+ if (MAX_STACK <= doc->where - doc->where_path) {
995
+ rb_raise(rb_const_get_at(Oj, rb_intern("DepthError")), "Path too deep. Limit is %d levels.", MAX_STACK);
996
+ }
991
997
  do {
992
998
  *doc->where = e;
993
999
  each_leaf(doc, self);
994
1000
  e = e->next;
995
1001
  } while (e != first);
1002
+ doc->where--;
996
1003
  }
997
1004
  } else {
998
1005
  rb_yield(self);
@@ -488,7 +488,10 @@ load_with_opts(VALUE input, Options copts) {
488
488
  *
489
489
  * Parses a JSON document String into a Hash, Array, String, Fixnum, Float,
490
490
  * true, false, or nil. Raises an exception if the JSON is malformed or the
491
- * classes specified are not valid.
491
+ * classes specified are not valid. If the string input is not a valid JSON
492
+ * document (an empty string is not a valid JSON document) an exception is
493
+ * raised.
494
+ *
492
495
  * @param [String] json JSON String
493
496
  * @param [Hash] options load options (same as default_options)
494
497
  */
@@ -508,9 +511,10 @@ load(int argc, VALUE *argv, VALUE self) {
508
511
  /* Document-method: load_file
509
512
  * call-seq: load_file(path, options) => Hash, Array, String, Fixnum, Float, true, false, or nil
510
513
  *
511
- * Parses a JSON document from a file into a Hash, Array, String, Fixnum,
512
- * Float, true, false, or nil. Raises an exception if the JSON is malformed or
513
- * the classes specified are not valid.
514
+ * Parses a JSON document from a file into a Hash, Array, String, Fixnum, Float,
515
+ * true, false, or nil. Raises an exception if the JSON is malformed or the
516
+ * classes specified are not valid. If the input file is not a valid JSON
517
+ * document (an empty file is not a valid JSON document) an exception is raised.
514
518
  *
515
519
  * @param [String] path path to a file containing a JSON document
516
520
  * @param [Hash] options load options (same as default_options)
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.0.13'
4
+ VERSION = '2.0.14'
5
5
  end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ reltypes={}
16
+ Oj::Doc.open_file('foo.json') do |doc|
17
+ doc.each_child do |target|
18
+ puts "#{target.local_key} is #{target.local_key.class}"
19
+ target.each_leaf do |score|
20
+ reltype=score.local_key
21
+ reltypes[reltype] = (reltypes[reltype] || 0) + 1
22
+ end
23
+ end
24
+ end
@@ -387,6 +387,15 @@ class DocTest < ::Test::Unit::TestCase
387
387
  assert_equal({'/1' => 1, '/2/1' => 2, '/2/2' => 3}, results)
388
388
  end
389
389
 
390
+ def test_each_leaf_hash
391
+ results = Oj::Doc.open('{"a":{"x":2},"b":{"y":4}}') do |doc|
392
+ h = {}
393
+ doc.each_leaf() { |d| h[d.where?] = d.fetch() }
394
+ h
395
+ end
396
+ assert_equal({'/a/x' => 2, '/b/y' => 4}, results)
397
+ end
398
+
390
399
  def test_comment
391
400
  json = %{{
392
401
  "x"/*one*/:/*two*/true,//three
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.0.13
4
+ version: 2.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-17 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com
@@ -25,7 +25,6 @@ files:
25
25
  - lib/oj/version.rb
26
26
  - lib/oj.rb
27
27
  - ext/oj/extconf.rb
28
- - ext/oj/foo.rb
29
28
  - ext/oj/cache.h
30
29
  - ext/oj/cache8.h
31
30
  - ext/oj/oj.h
@@ -39,6 +38,7 @@ files:
39
38
  - test/a.rb
40
39
  - test/bug.rb
41
40
  - test/files.rb
41
+ - test/foo.rb
42
42
  - test/mj.rb
43
43
  - test/perf.rb
44
44
  - test/perf1.rb
@@ -1,6 +0,0 @@
1
-
2
- def foo()
3
- [1, [true, false]].each { |x| yield x }
4
- end
5
-
6
- foo() { |x| puts x }