json 1.4.3-java → 1.4.4-java

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

Potentially problematic release.


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

Binary file
Binary file
@@ -70,24 +70,25 @@ module JSON
70
70
  # * *array_class*: Defaults to Array
71
71
  def initialize(source, opts = {})
72
72
  if defined?(::Encoding)
73
- if source.encoding == Encoding::ASCII_8BIT
73
+ if source.encoding == ::Encoding::ASCII_8BIT
74
74
  b = source[0, 4].bytes.to_a
75
75
  source = case
76
76
  when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
77
- source.dup.force_encoding(Encoding::UTF_32BE).encode!(Encoding::UTF_8)
77
+ source.dup.force_encoding(::Encoding::UTF_32BE).encode!(::Encoding::UTF_8)
78
78
  when b.size >= 4 && b[0] == 0 && b[2] == 0
79
- source.dup.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8)
79
+ source.dup.force_encoding(::Encoding::UTF_16BE).encode!(::Encoding::UTF_8)
80
80
  when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
81
- source.dup.force_encoding(Encoding::UTF_32LE).encode!(Encoding::UTF_8)
81
+ source.dup.force_encoding(::Encoding::UTF_32LE).encode!(::Encoding::UTF_8)
82
+
82
83
  when b.size >= 4 && b[1] == 0 && b[3] == 0
83
- source.dup.force_encoding(Encoding::UTF_16LE).encode!(Encoding::UTF_8)
84
+ source.dup.force_encoding(::Encoding::UTF_16LE).encode!(::Encoding::UTF_8)
84
85
  else
85
86
  source.dup
86
87
  end
87
88
  else
88
- source = source.encode(Encoding::UTF_8)
89
+ source = source.encode(::Encoding::UTF_8)
89
90
  end
90
- source.force_encoding(Encoding::ASCII_8BIT)
91
+ source.force_encoding(::Encoding::ASCII_8BIT)
91
92
  else
92
93
  b = source
93
94
  source = case
@@ -180,7 +181,7 @@ module JSON
180
181
  end
181
182
  end
182
183
  if string.respond_to?(:force_encoding)
183
- string.force_encoding(Encoding::UTF_8)
184
+ string.force_encoding(::Encoding::UTF_8)
184
185
  end
185
186
  string
186
187
  else
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.4.3'
3
+ VERSION = '1.4.4'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -160,6 +160,20 @@ class TC_JSON < Test::Unit::TestCase
160
160
 
161
161
  class SubArray < Array; end
162
162
 
163
+ class SubArray2 < Array
164
+ def to_json(*a)
165
+ {
166
+ JSON.create_id => self.class.name,
167
+ 'ary' => to_a,
168
+ }.to_json(*a)
169
+ end
170
+
171
+ def self.json_create(o)
172
+ o.delete JSON.create_id
173
+ o['ary']
174
+ end
175
+ end
176
+
163
177
  def test_parse_array_custom_class
164
178
  res = parse('[]', :array_class => SubArray)
165
179
  assert_equal([], res)
@@ -174,6 +188,9 @@ class TC_JSON < Test::Unit::TestCase
174
188
  end
175
189
 
176
190
  class SubHash < Hash
191
+ end
192
+
193
+ class SubHash2 < Hash
177
194
  def to_json(*a)
178
195
  {
179
196
  JSON.create_id => self.class.name,
@@ -182,22 +199,38 @@ class TC_JSON < Test::Unit::TestCase
182
199
 
183
200
  def self.json_create(o)
184
201
  o.delete JSON.create_id
185
- new.merge(o)
202
+ self[o]
186
203
  end
187
204
  end
188
205
 
189
206
  def test_parse_object_custom_class
190
- res = parse('{}', :object_class => SubHash)
207
+ res = parse('{}', :object_class => SubHash2)
191
208
  assert_equal({}, res)
192
- assert_equal(SubHash, res.class)
209
+ assert_equal(SubHash2, res.class)
210
+ end
211
+
212
+ def test_generation_of_core_subclasses_with_new_to_json
213
+ obj = SubHash2["foo" => SubHash2["bar" => true]]
214
+ obj_json = JSON(obj)
215
+ obj_again = JSON(obj_json)
216
+ assert_kind_of SubHash2, obj_again
217
+ assert_kind_of SubHash2, obj_again['foo']
218
+ assert obj_again['foo']['bar']
219
+ assert_equal obj, obj_again
220
+ assert_equal ["foo"], JSON(JSON(SubArray2["foo"]))
221
+ end
222
+
223
+ def test_generation_of_core_subclasses_with_default_to_json
224
+ assert_equal '{"foo":"bar"}', JSON(SubHash["foo" => "bar"])
225
+ assert_equal '["foo"]', JSON(SubArray["foo"])
193
226
  end
194
227
 
195
228
  def test_generation_of_core_subclasses
196
- obj = SubHash.new.merge( "foo" => SubHash.new.merge("bar" => true))
229
+ obj = SubHash["foo" => SubHash["bar" => true]]
197
230
  obj_json = JSON(obj)
198
231
  obj_again = JSON(obj_json)
199
- assert_kind_of SubHash, obj_again
200
- assert_kind_of SubHash, obj_again['foo']
232
+ assert_kind_of Hash, obj_again
233
+ assert_kind_of Hash, obj_again['foo']
201
234
  assert obj_again['foo']['bar']
202
235
  assert_equal obj, obj_again
203
236
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 3
9
- version: 1.4.3
8
+ - 4
9
+ version: 1.4.4
10
10
  platform: java
11
11
  authors:
12
12
  - Daniel Luz
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-03 00:00:00 -05:00
17
+ date: 2010-08-06 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20