json_pure 1.7.7 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fcee847ff7c0d00a38c2506b846d6795bfb2536
|
4
|
+
data.tar.gz: 0dc226f4f7c3f1ccfc0e5b1df624b89f324a1d97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7604bf969607d3c0ea3f96559a2a82d89c20d467a15611d01f94d2cf0e9809ad8bba0454eed065629bbd3754c12b6ed51fc8e50667cf3985910baaa591048d77
|
7
|
+
data.tar.gz: fcd3f79431eee7e47d749462d309c19778832ce3b61e2c1e0f9c2720455f4eff0946146a44776b9507051536018ac9e2d4841df743c62d13445896f4bc824420
|
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_pure
|
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
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -184,6 +177,7 @@ files:
|
|
184
177
|
homepage: http://flori.github.com/json
|
185
178
|
licenses:
|
186
179
|
- Ruby
|
180
|
+
metadata: {}
|
187
181
|
post_install_message:
|
188
182
|
rdoc_options:
|
189
183
|
- --title
|
@@ -193,25 +187,20 @@ rdoc_options:
|
|
193
187
|
require_paths:
|
194
188
|
- lib
|
195
189
|
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
-
none: false
|
197
190
|
requirements:
|
198
|
-
- -
|
191
|
+
- - '>='
|
199
192
|
- !ruby/object:Gem::Version
|
200
193
|
version: '0'
|
201
|
-
segments:
|
202
|
-
- 0
|
203
|
-
hash: -3737191669219953404
|
204
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
-
none: false
|
206
195
|
requirements:
|
207
|
-
- -
|
196
|
+
- - '>='
|
208
197
|
- !ruby/object:Gem::Version
|
209
198
|
version: '0'
|
210
199
|
requirements: []
|
211
200
|
rubyforge_project:
|
212
|
-
rubygems_version:
|
201
|
+
rubygems_version: 2.0.3
|
213
202
|
signing_key:
|
214
|
-
specification_version:
|
203
|
+
specification_version: 4
|
215
204
|
summary: JSON Implementation for Ruby
|
216
205
|
test_files:
|
217
206
|
- ./tests/test_json.rb
|