oj 3.11.2 → 3.11.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/ext/oj/buf.h +34 -38
  4. data/ext/oj/cache8.c +59 -62
  5. data/ext/oj/cache8.h +8 -7
  6. data/ext/oj/circarray.c +33 -35
  7. data/ext/oj/circarray.h +11 -9
  8. data/ext/oj/code.c +170 -174
  9. data/ext/oj/code.h +21 -20
  10. data/ext/oj/compat.c +159 -166
  11. data/ext/oj/custom.c +802 -851
  12. data/ext/oj/dump.c +766 -778
  13. data/ext/oj/dump.h +49 -51
  14. data/ext/oj/dump_compat.c +1 -0
  15. data/ext/oj/dump_leaf.c +116 -157
  16. data/ext/oj/dump_object.c +609 -628
  17. data/ext/oj/dump_strict.c +318 -327
  18. data/ext/oj/encode.h +3 -4
  19. data/ext/oj/err.c +39 -25
  20. data/ext/oj/err.h +24 -15
  21. data/ext/oj/extconf.rb +2 -1
  22. data/ext/oj/fast.c +1042 -1041
  23. data/ext/oj/hash.c +62 -66
  24. data/ext/oj/hash.h +7 -6
  25. data/ext/oj/hash_test.c +450 -443
  26. data/ext/oj/mimic_json.c +412 -402
  27. data/ext/oj/object.c +559 -528
  28. data/ext/oj/odd.c +123 -128
  29. data/ext/oj/odd.h +27 -25
  30. data/ext/oj/oj.c +1123 -922
  31. data/ext/oj/oj.h +286 -298
  32. data/ext/oj/parse.c +938 -930
  33. data/ext/oj/parse.h +70 -69
  34. data/ext/oj/rails.c +836 -839
  35. data/ext/oj/rails.h +7 -7
  36. data/ext/oj/reader.c +135 -140
  37. data/ext/oj/reader.h +66 -79
  38. data/ext/oj/resolve.c +43 -43
  39. data/ext/oj/resolve.h +3 -2
  40. data/ext/oj/rxclass.c +67 -68
  41. data/ext/oj/rxclass.h +12 -10
  42. data/ext/oj/saj.c +451 -479
  43. data/ext/oj/scp.c +93 -103
  44. data/ext/oj/sparse.c +770 -730
  45. data/ext/oj/stream_writer.c +120 -149
  46. data/ext/oj/strict.c +71 -86
  47. data/ext/oj/string_writer.c +198 -243
  48. data/ext/oj/trace.c +29 -33
  49. data/ext/oj/trace.h +14 -11
  50. data/ext/oj/util.c +103 -103
  51. data/ext/oj/util.h +3 -2
  52. data/ext/oj/val_stack.c +47 -47
  53. data/ext/oj/val_stack.h +79 -86
  54. data/ext/oj/wab.c +291 -309
  55. data/lib/oj/bag.rb +1 -0
  56. data/lib/oj/easy_hash.rb +5 -4
  57. data/lib/oj/mimic.rb +0 -12
  58. data/lib/oj/version.rb +1 -1
  59. data/test/activerecord/result_test.rb +7 -2
  60. data/test/foo.rb +8 -40
  61. data/test/test_fast.rb +32 -2
  62. data/test/test_generate.rb +21 -0
  63. data/test/test_hash.rb +10 -0
  64. data/test/test_scp.rb +1 -1
  65. metadata +4 -2
data/lib/oj/bag.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Oj
3
4
 
data/lib/oj/easy_hash.rb CHANGED
@@ -12,13 +12,14 @@ module Oj
12
12
 
13
13
  # Replaces the Object.respond_to?() method.
14
14
  # @param [Symbol] m method symbol
15
+ # @param [Boolean] include_all whether to include private and protected methods in the search
15
16
  # @return [Boolean] true for any method that matches an instance
16
17
  # variable reader, otherwise false.
17
- def respond_to?(m)
18
+ def respond_to?(m, include_all = false)
18
19
  return true if super
19
- return true if has_key?(key)
20
- return true if has_key?(key.to_s)
21
- has_key?(key.to_sym)
20
+ return true if has_key?(m)
21
+ return true if has_key?(m.to_s)
22
+ has_key?(m.to_sym)
22
23
  end
23
24
 
24
25
  def [](key)
data/lib/oj/mimic.rb CHANGED
@@ -133,18 +133,6 @@ module Oj
133
133
  end
134
134
  end
135
135
 
136
- Date.class_eval do
137
- # Both the JSON gem and Rails monkey patch as_json. Let them battle it out.
138
- unless defined?(self.as_json)
139
- def as_json(*)
140
- { JSON.create_id => 'Date', 'y' => year, 'm' => month, 'd' => day, 'sg' => start }
141
- end
142
- end
143
- def self.json_create(h)
144
- civil(h['y'], h['m'], h['d'], h['sg'])
145
- end
146
- end
147
-
148
136
  DateTime.class_eval do
149
137
  # Both the JSON gem and Rails monkey patch as_json. Let them battle it out.
150
138
  unless defined?(self.as_json)
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.11.2'
4
+ VERSION = '3.11.7'
5
5
  end
@@ -21,7 +21,12 @@ class ActiveRecordResultTest < Minitest::Test
21
21
  ["row 3 col 1", "row 3 col 2"],
22
22
  ])
23
23
  #puts "*** result: #{Oj.dump(result, indent: 2)}"
24
-
25
- assert_equal Oj.dump(result, mode: :rails), Oj.dump(result.to_hash)
24
+ json_result = if ActiveRecord.version >= Gem::Version.new("6")
25
+ result.to_a
26
+ else
27
+ result.to_hash
28
+ end
29
+
30
+ assert_equal Oj.dump(result, mode: :rails), Oj.dump(json_result)
26
31
  end
27
32
  end
data/test/foo.rb CHANGED
@@ -6,47 +6,15 @@ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
6
  $: << File.join($oj_dir, dir)
7
7
  end
8
8
 
9
- require 'json'
10
-
11
- t = [Time.now.utc]
12
-
13
- puts "t.to_json - #{t.to_json}"
14
-
15
- puts "--- active support"
16
-
17
- require 'active_support'
18
- require "active_support/json"
19
-
20
- ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
21
-
22
- puts "t.as_json - #{t.as_json}"
23
- puts "t.to_json - #{t.to_json}"
24
-
25
9
  require 'oj'
26
-
27
- t = [Time.now.utc]
28
-
29
- puts "-----------------------"
30
-
31
- #puts "t.as_json - #{t.as_json}"
32
- puts "t.to_json - #{t.to_json}"
33
-
34
- #Oj.mimic_JSON
35
-
36
- #puts "Oj - t.as_json - #{t.as_json}"
37
-
38
- puts "--- active support"
39
-
40
10
  require 'active_support'
41
- require "active_support/json"
42
-
43
- ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
44
-
45
- puts "t.as_json - #{t.as_json}"
46
- puts "t.to_json - #{t.to_json}"
47
11
 
48
- puts "--- optimize"
49
- Oj.optimize_rails
12
+ Oj.default_options = {trace: true}
50
13
 
51
- puts "t.as_json - #{t.as_json}"
52
- puts "t.to_json - #{t.to_json}"
14
+ Oj::Rails.mimic_JSON
15
+ #Oj.mimic_JSON
16
+ begin
17
+ ::JSON.load('foo=&bar')
18
+ rescue Exception => e
19
+ puts "*** #{e.class}: #{e.message}"
20
+ end
data/test/test_fast.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
4
  $: << File.dirname(__FILE__)
5
5
 
@@ -279,10 +279,26 @@ class DocTest < Minitest::Test
279
279
  ['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
280
280
  ['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
281
281
  ['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
282
+ ['/nothing', nil],
283
+ ['/array/10', nil],
282
284
  ].each do |path,val|
283
- assert_equal(val, doc.fetch(path))
285
+ if val.nil?
286
+ assert_nil(doc.fetch(path))
287
+ else
288
+ assert_equal(val, doc.fetch(path))
289
+ end
284
290
  end
285
291
  end
292
+ # verify empty hash and arrays return nil when a member is requested
293
+ Oj::Doc.open('{}') do |doc|
294
+ assert_nil(doc.fetch('/x'))
295
+ assert_nil(doc.fetch('/0'))
296
+ end
297
+ Oj::Doc.open('[]') do |doc|
298
+ assert_nil(doc.fetch('/x'))
299
+ assert_nil(doc.fetch('/0'))
300
+ end
301
+
286
302
  end
287
303
 
288
304
  def test_move_fetch_path
@@ -297,6 +313,20 @@ class DocTest < Minitest::Test
297
313
  end
298
314
  end
299
315
 
316
+ def test_exisits
317
+ Oj::Doc.open(@json1) do |doc|
318
+ [['/array/1', true],
319
+ ['/array/1', true],
320
+ ['/array/1/hash', true],
321
+ ['/array/1/dash', false],
322
+ ['/array/3', false],
323
+ ['/nothing', false],
324
+ ].each do |path,val|
325
+ assert_equal(val, doc.exists?(path))
326
+ end
327
+ end
328
+ end
329
+
300
330
  def test_home
301
331
  Oj::Doc.open(@json1) do |doc|
302
332
  doc.move('/array/1/num')
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
+ %w(lib ext).each do |dir|
7
+ $: << File.join($oj_dir, dir)
8
+ end
9
+
10
+ require 'minitest'
11
+ require 'minitest/autorun'
12
+ require 'oj'
13
+
14
+ class Generator < Minitest::Test
15
+
16
+ def test_before
17
+ json = Oj.generate({})
18
+ assert_equal("{}", json)
19
+ end
20
+
21
+ end
data/test/test_hash.rb CHANGED
@@ -25,5 +25,15 @@ class Hashi < Minitest::Test
25
25
  assert_equal(3, obj[:abc])
26
26
  assert_equal(3, obj.abc())
27
27
  end
28
+
29
+ def test_marshal
30
+ h = Oj::EasyHash.new()
31
+ h['abc'] = 3
32
+ out = Marshal.dump(h)
33
+
34
+ obj = Marshal.load(out)
35
+ assert_equal(Oj::EasyHash, obj.class)
36
+ assert_equal(3, obj[:abc])
37
+ end
28
38
 
29
39
  end # HashTest
data/test/test_scp.rb CHANGED
@@ -328,7 +328,7 @@ class ScpTest < Minitest::Test
328
328
  IO.pipe do |read_io, write_io|
329
329
  if fork
330
330
  write_io.close
331
- Oj.sc_parse(handler, read_io) {|v| p v}
331
+ Oj.sc_parse(handler, read_io)
332
332
  read_io.close
333
333
  assert_equal([[:hash_start],
334
334
  [:hash_key, 'one'],
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.11.2
4
+ version: 3.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -240,6 +240,7 @@ files:
240
240
  - test/test_fast.rb
241
241
  - test/test_file.rb
242
242
  - test/test_gc.rb
243
+ - test/test_generate.rb
243
244
  - test/test_hash.rb
244
245
  - test/test_integer_range.rb
245
246
  - test/test_null.rb
@@ -364,6 +365,7 @@ test_files:
364
365
  - test/test_fast.rb
365
366
  - test/test_file.rb
366
367
  - test/test_gc.rb
368
+ - test/test_generate.rb
367
369
  - test/test_hash.rb
368
370
  - test/test_integer_range.rb
369
371
  - test/test_null.rb