json 1.7.7 → 1.8.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/CHANGES +11 -1
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +15 -7
- data/java/src/json/ext/OptionsReader.java +3 -2
- data/json.gemspec +4 -4
- data/json_pure.gemspec +4 -4
- data/lib/json/generic_object.rb +9 -0
- data/lib/json/pure/generator.rb +32 -2
- data/lib/json/version.rb +1 -1
- data/tests/test_json_generate.rb +22 -0
- data/tests/test_json_generic_object.rb +15 -0
- metadata +9 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f7699d7a235e5ee1831e5dd162893ca440a2dff
|
4
|
+
data.tar.gz: 8a7dfdd7b9a809f87b99b1f82be2cfb239445ed9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8816837c8c09bb4a7337d8f9459cdb0f9d0b4e28698c7ccab16d4dfed21c96cdcc848f5a79390f4527a9393311f656bf1a02cc5ea5bd0362aa294fe5c35550c
|
7
|
+
data.tar.gz: 80394af8c38f184434a4c534ba5907e61d6fdf37960750a39f1cacc0b9120ee096d09c99f5ff1dbc6f64858f6af6b5ebbc6856ee5739f1c1e44ae012cc144663
|
data/.travis.yml
CHANGED
data/CHANGES
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2013-05-13 (1.8.0)
|
2
|
+
* Fix https://github.com/flori/json/issues/162 reported by Marc-Andre
|
3
|
+
Lafortune <github_rocks@marc-andre.ca>. Thanks!
|
4
|
+
* Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with
|
5
|
+
-Wchar-subscripts and better validate UTF-8 strings.
|
6
|
+
* Applied patch by ginriki@github to remove unnecessary if.
|
7
|
+
* Add load/dump interface to JSON::GenericObject to make
|
8
|
+
serialize :some_attribute, JSON::GenericObject
|
9
|
+
work in Rails active models for convenient SomeModel#some_attribute.foo.bar
|
10
|
+
access to serialised JSON data.
|
1
11
|
2013-02-04 (1.7.7)
|
2
12
|
* Security fix for JSON create_additions default value and
|
3
13
|
JSON::GenericObject. It should not be possible to create additions unless
|
@@ -5,7 +15,7 @@
|
|
5
15
|
using the JSON.load/dump interface. If JSON::GenericObject is supposed to
|
6
16
|
be automatically deserialised, this has to be explicitely enabled by
|
7
17
|
setting
|
8
|
-
JSON::GenericObject.
|
18
|
+
JSON::GenericObject.json_creatable = true
|
9
19
|
as well.
|
10
20
|
* Remove useless assert in fbuffer implementation.
|
11
21
|
* Apply patch attached to https://github.com/flori/json/issues#issue/155
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.0
|
@@ -273,7 +273,18 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
|
273
273
|
escape_len = 2;
|
274
274
|
break;
|
275
275
|
default:
|
276
|
-
|
276
|
+
{
|
277
|
+
unsigned short clen = trailingBytesForUTF8[c] + 1;
|
278
|
+
if (end + clen > len) {
|
279
|
+
rb_raise(rb_path2class("JSON::GeneratorError"),
|
280
|
+
"partial character in source, but hit end");
|
281
|
+
}
|
282
|
+
if (!isLegalUTF8((UTF8 *) p, clen)) {
|
283
|
+
rb_raise(rb_path2class("JSON::GeneratorError"),
|
284
|
+
"source sequence is illegal/malformed utf-8");
|
285
|
+
}
|
286
|
+
end += clen;
|
287
|
+
}
|
277
288
|
continue;
|
278
289
|
break;
|
279
290
|
}
|
@@ -511,11 +522,8 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
511
522
|
{
|
512
523
|
VALUE tmp;
|
513
524
|
GET_STATE(self);
|
514
|
-
tmp =
|
525
|
+
tmp = rb_check_convert_type(opts, T_HASH, "Hash", "to_hash");
|
515
526
|
if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h");
|
516
|
-
if (NIL_P(tmp)) {
|
517
|
-
rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash");
|
518
|
-
}
|
519
527
|
opts = tmp;
|
520
528
|
tmp = rb_hash_aref(opts, ID2SYM(i_indent));
|
521
529
|
if (RTEST(tmp)) {
|
@@ -894,8 +902,8 @@ static int isArrayOrObject(VALUE string)
|
|
894
902
|
long string_len = RSTRING_LEN(string);
|
895
903
|
char *p = RSTRING_PTR(string), *q = p + string_len - 1;
|
896
904
|
if (string_len < 2) return 0;
|
897
|
-
for (; p < q && isspace(*p); p++);
|
898
|
-
for (; q > p && isspace(*q); q--);
|
905
|
+
for (; p < q && isspace((unsigned char)*p); p++);
|
906
|
+
for (; q > p && isspace((unsigned char)*q); q--);
|
899
907
|
return (*p == '[' && *q == ']') || (*p == '{' && *q == '}');
|
900
908
|
}
|
901
909
|
|
@@ -24,13 +24,14 @@ final class OptionsReader {
|
|
24
24
|
OptionsReader(ThreadContext context, IRubyObject vOpts) {
|
25
25
|
this.context = context;
|
26
26
|
this.runtime = context.getRuntime();
|
27
|
-
|
28
27
|
if (vOpts == null || vOpts.isNil()) {
|
29
28
|
opts = null;
|
30
29
|
} else if (vOpts.respondsTo("to_hash")) {
|
31
30
|
opts = vOpts.convertToHash();
|
32
|
-
} else {
|
31
|
+
} else if (vOpts.respondsTo("to_h")) {
|
33
32
|
opts = vOpts.callMethod(context, "to_h").convertToHash();
|
33
|
+
} else {
|
34
|
+
opts = vOpts.convertToHash(); /* Should just raise the correct TypeError */
|
34
35
|
}
|
35
36
|
}
|
36
37
|
|
data/json.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "json"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.8.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Florian Frank"]
|
9
|
-
s.date = "2013-
|
9
|
+
s.date = "2013-05-13"
|
10
10
|
s.description = "This is a JSON implementation as a Ruby extension in C."
|
11
11
|
s.email = "flori@ping.de"
|
12
12
|
s.extensions = ["ext/json/ext/generator/extconf.rb", "ext/json/ext/parser/extconf.rb"]
|
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.licenses = ["Ruby"]
|
17
17
|
s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.rdoc"]
|
18
18
|
s.require_paths = ["lib"]
|
19
|
-
s.rubygems_version = "
|
19
|
+
s.rubygems_version = "2.0.3"
|
20
20
|
s.summary = "JSON Implementation for Ruby"
|
21
21
|
s.test_files = ["./tests/test_json.rb", "./tests/test_json_addition.rb", "./tests/test_json_encoding.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_generate.rb", "./tests/test_json_generic_object.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_unicode.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
|
-
s.specification_version =
|
24
|
+
s.specification_version = 4
|
25
25
|
|
26
26
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
27
|
s.add_development_dependency(%q<permutation>, [">= 0"])
|
data/json_pure.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "json_pure"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.8.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Florian Frank"]
|
9
|
-
s.date = "2013-
|
9
|
+
s.date = "2013-05-13"
|
10
10
|
s.description = "This is a JSON implementation in pure Ruby."
|
11
11
|
s.email = "flori@ping.de"
|
12
12
|
s.extra_rdoc_files = ["README.rdoc"]
|
@@ -15,12 +15,12 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.licenses = ["Ruby"]
|
16
16
|
s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
|
-
s.rubygems_version = "
|
18
|
+
s.rubygems_version = "2.0.3"
|
19
19
|
s.summary = "JSON Implementation for Ruby"
|
20
20
|
s.test_files = ["./tests/test_json.rb", "./tests/test_json_addition.rb", "./tests/test_json_encoding.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_generate.rb", "./tests/test_json_generic_object.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_unicode.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
s.specification_version =
|
23
|
+
s.specification_version = 4
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
26
|
s.add_development_dependency(%q<permutation>, [">= 0"])
|
data/lib/json/generic_object.rb
CHANGED
@@ -31,6 +31,15 @@ module JSON
|
|
31
31
|
object
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
def load(source, proc = nil, opts = {})
|
36
|
+
result = ::JSON.load(source, proc, opts.merge(:object_class => self))
|
37
|
+
result.nil? ? new : result
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump(obj, *args)
|
41
|
+
::JSON.dump(obj, *args)
|
42
|
+
end
|
34
43
|
end
|
35
44
|
self.json_creatable = false
|
36
45
|
|
data/lib/json/pure/generator.rb
CHANGED
@@ -70,6 +70,13 @@ module JSON
|
|
70
70
|
rescue => e
|
71
71
|
raise GeneratorError.wrap(e)
|
72
72
|
end
|
73
|
+
|
74
|
+
def valid_utf8?(string)
|
75
|
+
encoding = string.encoding
|
76
|
+
(encoding == Encoding::UTF_8 || encoding == Encoding::ASCII) &&
|
77
|
+
string.valid_encoding?
|
78
|
+
end
|
79
|
+
module_function :valid_utf8?
|
73
80
|
else
|
74
81
|
def utf8_to_json(string) # :nodoc:
|
75
82
|
string.gsub(/["\\\x0-\x1f]/n) { MAP[$&] }
|
@@ -93,8 +100,22 @@ module JSON
|
|
93
100
|
rescue => e
|
94
101
|
raise GeneratorError.wrap(e)
|
95
102
|
end
|
103
|
+
|
104
|
+
def valid_utf8?(string)
|
105
|
+
string =~
|
106
|
+
/\A( [\x09\x0a\x0d\x20-\x7e] # ASCII
|
107
|
+
| [\xc2-\xdf][\x80-\xbf] # non-overlong 2-byte
|
108
|
+
| \xe0[\xa0-\xbf][\x80-\xbf] # excluding overlongs
|
109
|
+
| [\xe1-\xec\xee\xef][\x80-\xbf]{2} # straight 3-byte
|
110
|
+
| \xed[\x80-\x9f][\x80-\xbf] # excluding surrogates
|
111
|
+
| \xf0[\x90-\xbf][\x80-\xbf]{2} # planes 1-3
|
112
|
+
| [\xf1-\xf3][\x80-\xbf]{3} # planes 4-15
|
113
|
+
| \xf4[\x80-\x8f][\x80-\xbf]{2} # plane 16
|
114
|
+
)*\z/nx
|
115
|
+
end
|
96
116
|
end
|
97
|
-
module_function :utf8_to_json, :utf8_to_json_ascii
|
117
|
+
module_function :utf8_to_json, :utf8_to_json_ascii, :valid_utf8?
|
118
|
+
|
98
119
|
|
99
120
|
module Pure
|
100
121
|
module Generator
|
@@ -220,6 +241,13 @@ module JSON
|
|
220
241
|
# Configure this State instance with the Hash _opts_, and return
|
221
242
|
# itself.
|
222
243
|
def configure(opts)
|
244
|
+
if opts.respond_to?(:to_hash)
|
245
|
+
opts = opts.to_hash
|
246
|
+
elsif opts.respond_to?(:to_h)
|
247
|
+
opts = opts.to_h
|
248
|
+
else
|
249
|
+
raise TypeError, "can't convert #{opts.class} into Hash"
|
250
|
+
end
|
223
251
|
for key, value in opts
|
224
252
|
instance_variable_set "@#{key}", value
|
225
253
|
end
|
@@ -263,6 +291,8 @@ module JSON
|
|
263
291
|
# GeneratorError exception.
|
264
292
|
def generate(obj)
|
265
293
|
result = obj.to_json(self)
|
294
|
+
JSON.valid_utf8?(result) or raise GeneratorError,
|
295
|
+
"source sequence #{result.inspect} is illegal/malformed utf-8"
|
266
296
|
unless @quirks_mode
|
267
297
|
unless result =~ /\A\s*\[/ && result =~ /\]\s*\Z/ ||
|
268
298
|
result =~ /\A\s*\{/ && result =~ /\}\s*\Z/
|
@@ -338,7 +368,7 @@ module JSON
|
|
338
368
|
}
|
339
369
|
depth = state.depth -= 1
|
340
370
|
result << state.object_nl
|
341
|
-
result << state.indent * depth if indent
|
371
|
+
result << state.indent * depth if indent
|
342
372
|
result << '}'
|
343
373
|
result
|
344
374
|
end
|
data/lib/json/version.rb
CHANGED
data/tests/test_json_generate.rb
CHANGED
@@ -251,6 +251,22 @@ EOT
|
|
251
251
|
assert_equal '5', state2.array_nl
|
252
252
|
end
|
253
253
|
|
254
|
+
def test_configure_hash_conversion
|
255
|
+
state = JSON.state.new
|
256
|
+
state.configure(:indent => '1')
|
257
|
+
assert_equal '1', state.indent
|
258
|
+
state = JSON.state.new
|
259
|
+
foo = 'foo'
|
260
|
+
assert_raise(TypeError) do
|
261
|
+
state.configure(foo)
|
262
|
+
end
|
263
|
+
def foo.to_h
|
264
|
+
{ :indent => '2' }
|
265
|
+
end
|
266
|
+
state.configure(foo)
|
267
|
+
assert_equal '2', state.indent
|
268
|
+
end
|
269
|
+
|
254
270
|
if defined?(JSON::Ext::Generator)
|
255
271
|
def test_broken_bignum # [ruby-core:38867]
|
256
272
|
pid = fork do
|
@@ -297,4 +313,10 @@ EOT
|
|
297
313
|
assert_kind_of Hash, state_hash
|
298
314
|
assert_equal :bar, state_hash[:foo]
|
299
315
|
end
|
316
|
+
|
317
|
+
def test_json_generate
|
318
|
+
assert_raise JSON::GeneratorError do
|
319
|
+
assert_equal true, JSON.generate(["\xea"])
|
320
|
+
end
|
321
|
+
end
|
300
322
|
end
|
@@ -49,6 +49,21 @@ class TestJSONGenericObject < Test::Unit::TestCase
|
|
49
49
|
assert_equal true, GenericObject.from_hash(true)
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_json_generic_object_load
|
53
|
+
empty = JSON::GenericObject.load(nil)
|
54
|
+
assert_kind_of JSON::GenericObject, empty
|
55
|
+
simple_json = '{"json_class":"JSON::GenericObject","hello":"world"}'
|
56
|
+
simple = JSON::GenericObject.load(simple_json)
|
57
|
+
assert_kind_of JSON::GenericObject, simple
|
58
|
+
assert_equal "world", simple.hello
|
59
|
+
converting = JSON::GenericObject.load('{ "hello": "world" }')
|
60
|
+
assert_kind_of JSON::GenericObject, converting
|
61
|
+
assert_equal "world", converting.hello
|
62
|
+
|
63
|
+
json = JSON::GenericObject.dump(JSON::GenericObject[:hello => 'world'])
|
64
|
+
assert_equal JSON(json), JSON('{"json_class":"JSON::GenericObject","hello":"world"}')
|
65
|
+
end
|
66
|
+
|
52
67
|
private
|
53
68
|
|
54
69
|
def switch_json_creatable
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Florian Frank
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: permutation
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: sdoc
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -170,6 +165,7 @@ files:
|
|
170
165
|
homepage: http://flori.github.com/json
|
171
166
|
licenses:
|
172
167
|
- Ruby
|
168
|
+
metadata: {}
|
173
169
|
post_install_message:
|
174
170
|
rdoc_options:
|
175
171
|
- --title
|
@@ -179,25 +175,20 @@ rdoc_options:
|
|
179
175
|
require_paths:
|
180
176
|
- lib
|
181
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
-
none: false
|
183
178
|
requirements:
|
184
|
-
- -
|
179
|
+
- - '>='
|
185
180
|
- !ruby/object:Gem::Version
|
186
181
|
version: '0'
|
187
|
-
segments:
|
188
|
-
- 0
|
189
|
-
hash: -3737191669219953404
|
190
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
-
none: false
|
192
183
|
requirements:
|
193
|
-
- -
|
184
|
+
- - '>='
|
194
185
|
- !ruby/object:Gem::Version
|
195
186
|
version: '0'
|
196
187
|
requirements: []
|
197
188
|
rubyforge_project:
|
198
|
-
rubygems_version:
|
189
|
+
rubygems_version: 2.0.3
|
199
190
|
signing_key:
|
200
|
-
specification_version:
|
191
|
+
specification_version: 4
|
201
192
|
summary: JSON Implementation for Ruby
|
202
193
|
test_files:
|
203
194
|
- ./tests/test_json.rb
|