json 2.2.0 → 2.3.1

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,7 +66,7 @@ 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
@@ -197,7 +197,15 @@ module JSON
197
197
  def parse_value
198
198
  case
199
199
  when scan(FLOAT)
200
- @decimal_class && @decimal_class.new(self[1]) || 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
201
209
  when scan(INTEGER)
202
210
  Integer(self[1])
203
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.2.0'
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:
@@ -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
@@ -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
@@ -91,27 +91,27 @@ class JSONParserTest < Test::Unit::TestCase
91
91
  assert_raise(JSON::ParserError) { parse('+23') }
92
92
  assert_raise(JSON::ParserError) { parse('.23') }
93
93
  assert_raise(JSON::ParserError) { parse('023') }
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')
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'))
104
104
  assert_raise(ParserError) { parse('NaN') }
105
105
  assert parse('NaN', :allow_nan => true).nan?
106
106
  assert_raise(ParserError) { parse('Infinity') }
107
- assert_equal 1.0/0, parse('Infinity', :allow_nan => true)
107
+ assert_equal(1.0/0, parse('Infinity', :allow_nan => true))
108
108
  assert_raise(ParserError) { parse('-Infinity') }
109
- assert_equal -1.0/0, parse('-Infinity', :allow_nan => true)
109
+ assert_equal(-1.0/0, parse('-Infinity', :allow_nan => true))
110
110
  end
111
111
 
112
112
  def test_parse_bigdecimals
113
- assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
114
- assert_equal(BigDecimal.new("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
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"] )
115
115
  end
116
116
 
117
117
  if Array.method_defined?(:permutation)
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.2.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 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
  name: rake
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '4.0'
34
37
  type: :development
35
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: This is a JSON implementation as a Ruby extension in C.
42
48
  email: flori@ping.de
43
49
  executables: []
@@ -48,7 +54,6 @@ extensions:
48
54
  extra_rdoc_files:
49
55
  - README.md
50
56
  files:
51
- - "./tests/test_helper.rb"
52
57
  - ".gitignore"
53
58
  - ".travis.yml"
54
59
  - CHANGES.md
@@ -157,8 +162,14 @@ files:
157
162
  homepage: http://flori.github.com/json
158
163
  licenses:
159
164
  - Ruby
160
- metadata: {}
161
- post_install_message:
165
+ metadata:
166
+ bug_tracker_uri: https://github.com/flori/json/issues
167
+ changelog_uri: https://github.com/flori/json/blob/master/CHANGES.md
168
+ documentation_uri: http://flori.github.io/json/doc/index.html
169
+ homepage_uri: http://flori.github.io/json/
170
+ source_code_uri: https://github.com/flori/json
171
+ wiki_uri: https://github.com/flori/json/wiki
172
+ post_install_message:
162
173
  rdoc_options:
163
174
  - "--title"
164
175
  - JSON implemention for Ruby
@@ -170,16 +181,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
181
  requirements:
171
182
  - - ">="
172
183
  - !ruby/object:Gem::Version
173
- version: '1.9'
184
+ version: '2.0'
174
185
  required_rubygems_version: !ruby/object:Gem::Requirement
175
186
  requirements:
176
187
  - - ">="
177
188
  - !ruby/object:Gem::Version
178
189
  version: '0'
179
190
  requirements: []
180
- rubygems_version: 3.0.2
181
- signing_key:
191
+ rubygems_version: 3.1.2
192
+ signing_key:
182
193
  specification_version: 4
183
194
  summary: JSON Implementation for Ruby
184
195
  test_files:
185
- - "./tests/test_helper.rb"
196
+ - tests/test_helper.rb