json 2.0.3-java → 2.3.1-java

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.
@@ -250,7 +250,8 @@ module JSON
250
250
  if respond_to?(name)
251
251
  __send__(name)
252
252
  else
253
- instance_variable_get("@#{name}")
253
+ instance_variable_get("@#{name}") if
254
+ instance_variables.include?("@#{name}".to_sym) # avoid warning
254
255
  end
255
256
  end
256
257
 
@@ -404,7 +405,7 @@ module JSON
404
405
  end
405
406
  end
406
407
 
407
- # Module that holds the extinding methods if, the String module is
408
+ # Module that holds the extending methods if, the String module is
408
409
  # included.
409
410
  module Extend
410
411
  # Raw Strings are JSON Objects (the raw bytes are stored in an
@@ -49,7 +49,7 @@ module JSON
49
49
  )+
50
50
  )mx
51
51
 
52
- UNPARSED = Object.new.freeze
52
+ UNPARSED = Object.new.freeze
53
53
 
54
54
  # Creates a new JSON::Pure::Parser instance for the string _source_.
55
55
  #
@@ -66,10 +66,13 @@ module JSON
66
66
  # also the default. It's not possible to use this option in
67
67
  # conjunction with the *create_additions* option.
68
68
  # * *create_additions*: If set to true, the Parser creates
69
- # additions when if a matching class and create_id was found. This
69
+ # additions when a matching class and create_id are found. This
70
70
  # option defaults to false.
71
71
  # * *object_class*: Defaults to Hash
72
72
  # * *array_class*: Defaults to Array
73
+ # * *decimal_class*: Specifies which class to use instead of the default
74
+ # (Float) when parsing decimal numbers. This class must accept a single
75
+ # string argument in its constructor.
73
76
  def initialize(source, opts = {})
74
77
  opts ||= {}
75
78
  source = convert_encoding source
@@ -94,6 +97,7 @@ module JSON
94
97
  @create_id = @create_additions ? JSON.create_id : nil
95
98
  @object_class = opts[:object_class] || Hash
96
99
  @array_class = opts[:array_class] || Array
100
+ @decimal_class = opts[:decimal_class]
97
101
  @match_string = opts[:match_string]
98
102
  end
99
103
 
@@ -193,7 +197,15 @@ module JSON
193
197
  def parse_value
194
198
  case
195
199
  when scan(FLOAT)
196
- Float(self[1])
200
+ if @decimal_class then
201
+ if @decimal_class == BigDecimal then
202
+ BigDecimal(self[1])
203
+ else
204
+ @decimal_class.new(self[1]) || Float(self[1])
205
+ end
206
+ else
207
+ Float(self[1])
208
+ end
197
209
  when scan(INTEGER)
198
210
  Integer(self[1])
199
211
  when scan(TRUE)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  module JSON
3
3
  # JSON version
4
- VERSION = '2.0.3'
4
+ VERSION = '2.3.1'
5
5
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
6
6
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
7
7
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -5,6 +5,7 @@ require 'json/add/complex'
5
5
  require 'json/add/rational'
6
6
  require 'json/add/bigdecimal'
7
7
  require 'json/add/ostruct'
8
+ require 'json/add/set'
8
9
  require 'date'
9
10
 
10
11
  class JSONAdditionTest < Test::Unit::TestCase
@@ -190,4 +191,13 @@ class JSONAdditionTest < Test::Unit::TestCase
190
191
  o.foo = { 'bar' => true }
191
192
  assert_equal o, parse(JSON(o), :create_additions => true)
192
193
  end
194
+
195
+ def test_set
196
+ s = Set.new([:a, :b, :c, :a])
197
+ assert_equal s, JSON.parse(JSON(s), :create_additions => true)
198
+ ss = SortedSet.new([:d, :b, :a, :c])
199
+ ss_again = JSON.parse(JSON(ss), :create_additions => true)
200
+ assert_kind_of ss.class, ss_again
201
+ assert_equal ss, ss_again
202
+ end
193
203
  end
@@ -27,15 +27,15 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
27
27
  end
28
28
 
29
29
  def test_parser
30
- assert_match /::Parser\z/, JSON.parser.name
30
+ assert_match(/::Parser\z/, JSON.parser.name)
31
31
  end
32
32
 
33
33
  def test_generator
34
- assert_match /::Generator\z/, JSON.generator.name
34
+ assert_match(/::Generator\z/, JSON.generator.name)
35
35
  end
36
36
 
37
37
  def test_state
38
- assert_match /::Generator::State\z/, JSON.state.name
38
+ assert_match(/::Generator::State\z/, JSON.state.name)
39
39
  end
40
40
 
41
41
  def test_create_id
@@ -56,7 +56,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  def test_parse_bang
59
- assert_equal [ 1, NaN, 3, ], JSON.parse!('[ 1, NaN, 3 ]')
59
+ assert_equal [ 1, Infinity, 3, ], JSON.parse!('[ 1, Infinity, 3 ]')
60
60
  end
61
61
 
62
62
  def test_generate
@@ -79,6 +79,8 @@ class JSONEncodingTest < Test::Unit::TestCase
79
79
  json = '["\ud840\udc01"]'
80
80
  assert_equal json, generate(utf8, :ascii_only => true)
81
81
  assert_equal utf8, parse(json)
82
+ assert_raise(JSON::ParserError) { parse('"\u"') }
83
+ assert_raise(JSON::ParserError) { parse('"\ud800"') }
82
84
  end
83
85
 
84
86
  def test_chars
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
 
4
4
  class JSONFixturesTest < Test::Unit::TestCase
5
5
  def setup
6
- fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}.json')
6
+ fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}*.json')
7
7
  passed, failed = Dir[fixtures].partition { |f| f['pass'] }
8
8
  @passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
9
9
  @failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
@@ -29,4 +29,9 @@ class JSONFixturesTest < Test::Unit::TestCase
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ def test_sanity
34
+ assert(@passed.size > 5)
35
+ assert(@failed.size > 20)
36
+ end
32
37
  end
@@ -40,6 +40,44 @@ class JSONGeneratorTest < Test::Unit::TestCase
40
40
  EOT
41
41
  end
42
42
 
43
+ def silence
44
+ v = $VERBOSE
45
+ $VERBOSE = nil
46
+ yield
47
+ ensure
48
+ $VERBOSE = v
49
+ end
50
+
51
+ def test_remove_const_segv
52
+ return if RUBY_ENGINE == 'jruby'
53
+ stress = GC.stress
54
+ const = JSON::SAFE_STATE_PROTOTYPE.dup
55
+
56
+ bignum_too_long_to_embed_as_string = 1234567890123456789012345
57
+ expect = bignum_too_long_to_embed_as_string.to_s
58
+ GC.stress = true
59
+
60
+ 10.times do |i|
61
+ tmp = bignum_too_long_to_embed_as_string.to_json
62
+ raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
63
+ end
64
+
65
+ silence do
66
+ JSON.const_set :SAFE_STATE_PROTOTYPE, nil
67
+ end
68
+
69
+ 10.times do |i|
70
+ assert_raise TypeError do
71
+ bignum_too_long_to_embed_as_string.to_json
72
+ end
73
+ end
74
+ ensure
75
+ GC.stress = stress
76
+ silence do
77
+ JSON.const_set :SAFE_STATE_PROTOTYPE, const
78
+ end
79
+ end if JSON.const_defined?("Ext")
80
+
43
81
  def test_generate
44
82
  json = generate(@hash)
45
83
  assert_equal(parse(@json2), parse(json))
@@ -374,4 +412,10 @@ EOT
374
412
  assert_equal '["foo"]', JSON.generate([s.new('foo')])
375
413
  end
376
414
  end
415
+
416
+ if defined?(Encoding)
417
+ def test_nonutf8_encoding
418
+ assert_equal("\"5\u{b0}\"", "5\xb0".force_encoding("iso-8859-1").to_json)
419
+ end
420
+ end
377
421
  end
@@ -4,6 +4,7 @@ require 'test_helper'
4
4
  require 'stringio'
5
5
  require 'tempfile'
6
6
  require 'ostruct'
7
+ require 'bigdecimal'
7
8
 
8
9
  class JSONParserTest < Test::Unit::TestCase
9
10
  include JSON
@@ -90,22 +91,27 @@ class JSONParserTest < Test::Unit::TestCase
90
91
  assert_raise(JSON::ParserError) { parse('+23') }
91
92
  assert_raise(JSON::ParserError) { parse('.23') }
92
93
  assert_raise(JSON::ParserError) { parse('023') }
93
- assert_equal 23, parse('23')
94
- assert_equal -23, parse('-23')
95
- assert_equal_float 3.141, parse('3.141')
96
- assert_equal_float -3.141, parse('-3.141')
97
- assert_equal_float 3.141, parse('3141e-3')
98
- assert_equal_float 3.141, parse('3141.1e-3')
99
- assert_equal_float 3.141, parse('3141E-3')
100
- assert_equal_float 3.141, parse('3141.0E-3')
101
- assert_equal_float -3.141, parse('-3141.0e-3')
102
- assert_equal_float -3.141, parse('-3141e-3')
94
+ assert_equal(23, parse('23'))
95
+ assert_equal(-23, parse('-23'))
96
+ assert_equal_float(3.141, parse('3.141'))
97
+ assert_equal_float(-3.141, parse('-3.141'))
98
+ assert_equal_float(3.141, parse('3141e-3'))
99
+ assert_equal_float(3.141, parse('3141.1e-3'))
100
+ assert_equal_float(3.141, parse('3141E-3'))
101
+ assert_equal_float(3.141, parse('3141.0E-3'))
102
+ assert_equal_float(-3.141, parse('-3141.0e-3'))
103
+ assert_equal_float(-3.141, parse('-3141e-3'))
103
104
  assert_raise(ParserError) { parse('NaN') }
104
105
  assert parse('NaN', :allow_nan => true).nan?
105
106
  assert_raise(ParserError) { parse('Infinity') }
106
- assert_equal 1.0/0, parse('Infinity', :allow_nan => true)
107
+ assert_equal(1.0/0, parse('Infinity', :allow_nan => true))
107
108
  assert_raise(ParserError) { parse('-Infinity') }
108
- assert_equal -1.0/0, parse('-Infinity', :allow_nan => true)
109
+ assert_equal(-1.0/0, parse('-Infinity', :allow_nan => true))
110
+ end
111
+
112
+ def test_parse_bigdecimals
113
+ assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
114
+ assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
109
115
  end
110
116
 
111
117
  if Array.method_defined?(:permutation)
@@ -15,7 +15,3 @@ begin
15
15
  require 'byebug'
16
16
  rescue LoadError
17
17
  end
18
- if ENV['START_SIMPLECOV'].to_i == 1
19
- require 'simplecov'
20
- SimpleCov.start
21
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.3.1
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -17,8 +17,8 @@ dependencies:
17
17
  - !ruby/object:Gem::Version
18
18
  version: '0'
19
19
  name: rake
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
@@ -27,17 +27,23 @@ dependencies:
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '4.0'
33
36
  name: test-unit
34
- prerelease: false
35
37
  type: :development
38
+ prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '2.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
41
47
  description: A JSON implementation as a JRuby extension.
42
48
  email: dev+ruby@mernen.com
43
49
  executables: []
@@ -55,13 +61,12 @@ files:
55
61
  - lib/json/add/range.rb
56
62
  - lib/json/add/rational.rb
57
63
  - lib/json/add/regexp.rb
64
+ - lib/json/add/set.rb
58
65
  - lib/json/add/struct.rb
59
66
  - lib/json/add/symbol.rb
60
67
  - lib/json/add/time.rb
61
68
  - lib/json/common.rb
62
69
  - lib/json/ext.rb
63
- - lib/json/ext/generator.jar
64
- - lib/json/ext/parser.jar
65
70
  - lib/json/generic_object.rb
66
71
  - lib/json/pure.rb
67
72
  - lib/json/pure/generator.rb
@@ -108,7 +113,7 @@ files:
108
113
  - tests/json_parser_test.rb
109
114
  - tests/json_string_matching_test.rb
110
115
  - tests/test_helper.rb
111
- homepage: http://json-jruby.rubyforge.org/
116
+ homepage: http://flori.github.com/json
112
117
  licenses:
113
118
  - Ruby
114
119
  metadata: {}
@@ -127,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
132
  - !ruby/object:Gem::Version
128
133
  version: '0'
129
134
  requirements: []
130
- rubyforge_project: json-jruby
131
- rubygems_version: 2.6.8
135
+ rubygems_version: 3.0.6
132
136
  signing_key:
133
137
  specification_version: 4
134
138
  summary: JSON implementation for JRuby
Binary file
Binary file