json 1.0.0 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +503 -0
- data/LICENSE +56 -0
- data/README.md +416 -0
- data/ext/json/ext/fbuffer/fbuffer.h +187 -0
- data/ext/json/ext/generator/depend +1 -0
- data/ext/json/ext/generator/extconf.rb +2 -7
- data/ext/json/ext/generator/generator.c +1312 -338
- data/ext/json/ext/generator/generator.h +177 -0
- data/ext/json/ext/parser/depend +1 -0
- data/ext/json/ext/parser/extconf.rb +28 -5
- data/ext/json/ext/parser/parser.c +1349 -689
- data/ext/json/ext/parser/parser.h +96 -0
- data/ext/json/ext/parser/parser.rl +644 -188
- data/ext/json/extconf.rb +3 -0
- data/json.gemspec +68 -0
- data/lib/json/add/bigdecimal.rb +58 -0
- data/lib/json/add/complex.rb +51 -0
- data/lib/json/add/core.rb +12 -0
- data/lib/json/add/date.rb +54 -0
- data/lib/json/add/date_time.rb +67 -0
- data/lib/json/add/exception.rb +49 -0
- data/lib/json/add/ostruct.rb +54 -0
- data/lib/json/add/range.rb +54 -0
- data/lib/json/add/rational.rb +49 -0
- data/lib/json/add/regexp.rb +48 -0
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/struct.rb +52 -0
- data/lib/json/add/symbol.rb +48 -0
- data/lib/json/add/time.rb +59 -0
- data/lib/json/common.rb +588 -74
- data/lib/json/ext.rb +3 -1
- data/lib/json/generic_object.rb +75 -0
- data/lib/json/pure/generator.rb +311 -119
- data/lib/json/pure/parser.rb +182 -55
- data/lib/json/pure.rb +5 -65
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +583 -196
- metadata +78 -137
- data/CHANGES +0 -25
- data/GPL +0 -340
- data/README +0 -77
- data/Rakefile +0 -250
- data/TODO +0 -1
- data/VERSION +0 -1
- data/benchmarks/benchmark.txt +0 -133
- data/benchmarks/benchmark_generator.rb +0 -44
- data/benchmarks/benchmark_parser.rb +0 -22
- data/benchmarks/benchmark_rails.rb +0 -26
- data/bin/edit_json.rb +0 -11
- data/data/example.json +0 -1
- data/data/index.html +0 -37
- data/data/prototype.js +0 -2515
- data/ext/json/ext/generator/Makefile +0 -149
- data/ext/json/ext/generator/unicode.c +0 -184
- data/ext/json/ext/generator/unicode.h +0 -40
- data/ext/json/ext/parser/Makefile +0 -149
- data/ext/json/ext/parser/unicode.c +0 -156
- data/ext/json/ext/parser/unicode.h +0 -44
- data/install.rb +0 -26
- data/lib/json/Array.xpm +0 -21
- data/lib/json/FalseClass.xpm +0 -21
- data/lib/json/Hash.xpm +0 -21
- data/lib/json/Key.xpm +0 -73
- data/lib/json/NilClass.xpm +0 -21
- data/lib/json/Numeric.xpm +0 -28
- data/lib/json/String.xpm +0 -96
- data/lib/json/TrueClass.xpm +0 -21
- data/lib/json/editor.rb +0 -1207
- data/lib/json/json.xpm +0 -1499
- data/tests/fixtures/fail1.json +0 -1
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail15.json +0 -1
- data/tests/fixtures/fail16.json +0 -1
- data/tests/fixtures/fail17.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail26.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass18.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/runner.rb +0 -24
- data/tests/test_json.rb +0 -235
- data/tests/test_json_addition.rb +0 -94
- data/tests/test_json_fixtures.rb +0 -30
- data/tests/test_json_generate.rb +0 -81
- data/tests/test_json_unicode.rb +0 -55
- data/tools/fuzz.rb +0 -133
- data/tools/server.rb +0 -62
data/tests/test_json_unicode.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
class TC_JSONUnicode < Test::Unit::TestCase
|
7
|
-
include JSON
|
8
|
-
|
9
|
-
def setup
|
10
|
-
$KCODE = 'UTF8'
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_unicode
|
14
|
-
assert_equal '""', ''.to_json
|
15
|
-
assert_equal '"\\b"', "\b".to_json
|
16
|
-
assert_equal '"\u0001"', 0x1.chr.to_json
|
17
|
-
assert_equal '"\u001f"', 0x1f.chr.to_json
|
18
|
-
assert_equal '" "', ' '.to_json
|
19
|
-
assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
|
20
|
-
utf8 = [ "© ≠ €! \01" ]
|
21
|
-
json = '["\u00a9 \u2260 \u20ac! \u0001"]'
|
22
|
-
assert_equal json, utf8.to_json
|
23
|
-
assert_equal utf8, parse(json)
|
24
|
-
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
25
|
-
json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
|
26
|
-
assert_equal json, utf8.to_json
|
27
|
-
assert_equal utf8, parse(json)
|
28
|
-
utf8 = ['საქართველო']
|
29
|
-
json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
|
30
|
-
assert_equal json, utf8.to_json
|
31
|
-
assert_equal utf8, parse(json)
|
32
|
-
assert_equal '["\\u00c3"]', JSON.generate(["Ã"])
|
33
|
-
assert_equal ["€"], JSON.parse('["\u20ac"]')
|
34
|
-
utf8 = ["\xf0\xa0\x80\x81"]
|
35
|
-
json = '["\ud840\udc01"]'
|
36
|
-
assert_equal json, JSON.generate(utf8)
|
37
|
-
assert_equal utf8, JSON.parse(json)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_chars
|
41
|
-
(0..0x7f).each do |i|
|
42
|
-
json = '["\u%04x"]' % i
|
43
|
-
assert_equal i, JSON.parse(json).first[0]
|
44
|
-
if [?\b, ?\n, ?\r, ?\t, ?\f].include?(i)
|
45
|
-
assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
|
46
|
-
elsif i < 0x20
|
47
|
-
assert_equal json, JSON.generate(["" << i])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
assert_raises(JSON::GeneratorError) do
|
51
|
-
JSON.generate(["" << 0x80])
|
52
|
-
end
|
53
|
-
assert_equal "\302\200", JSON.parse('["\u0080"]').first
|
54
|
-
end
|
55
|
-
end
|
data/tools/fuzz.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
$KCODE='UTF8'
|
2
|
-
require 'json'
|
3
|
-
require 'irb'
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
class Fuzzer
|
7
|
-
def initialize(n, freqs = {})
|
8
|
-
sum = freqs.inject(0.0) { |s, x| s + x.last }
|
9
|
-
freqs.each_key { |x| freqs[x] /= sum }
|
10
|
-
s = 0.0
|
11
|
-
freqs.each_key do |x|
|
12
|
-
freqs[x] = s .. (s + t = freqs[x])
|
13
|
-
s += t
|
14
|
-
end
|
15
|
-
@freqs = freqs
|
16
|
-
@n = n
|
17
|
-
@alpha = (0..0x7f).to_a
|
18
|
-
end
|
19
|
-
|
20
|
-
def random_string
|
21
|
-
s = ''
|
22
|
-
30.times { s << @alpha[rand(@alpha.size)] }
|
23
|
-
s
|
24
|
-
end
|
25
|
-
|
26
|
-
def pick
|
27
|
-
r = rand
|
28
|
-
found = @freqs.find { |k, f| f.include? rand }
|
29
|
-
found && found.first
|
30
|
-
end
|
31
|
-
|
32
|
-
def make_pick
|
33
|
-
k = pick
|
34
|
-
case
|
35
|
-
when k == Hash, k == Array
|
36
|
-
k.new
|
37
|
-
when k == true, k == false, k == nil
|
38
|
-
k
|
39
|
-
when k == String
|
40
|
-
random_string
|
41
|
-
when k == Fixnum
|
42
|
-
rand(2 ** 30) - 2 ** 29
|
43
|
-
when k == Bignum
|
44
|
-
rand(2 ** 70) - 2 ** 69
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def fuzz(current = nil)
|
49
|
-
if @n > 0
|
50
|
-
case current
|
51
|
-
when nil
|
52
|
-
@n -= 1
|
53
|
-
current = fuzz [ Hash, Array ][rand(2)].new
|
54
|
-
when Array
|
55
|
-
while @n > 0
|
56
|
-
@n -= 1
|
57
|
-
current << case p = make_pick
|
58
|
-
when Array, Hash
|
59
|
-
fuzz(p)
|
60
|
-
else
|
61
|
-
p
|
62
|
-
end
|
63
|
-
end
|
64
|
-
when Hash
|
65
|
-
while @n > 0
|
66
|
-
@n -= 1
|
67
|
-
current[random_string] = case p = make_pick
|
68
|
-
when Array, Hash
|
69
|
-
fuzz(p)
|
70
|
-
else
|
71
|
-
p
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
current
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class MyState < JSON.state
|
81
|
-
WS = " \r\t\n"
|
82
|
-
|
83
|
-
def initialize
|
84
|
-
super(
|
85
|
-
:indent => make_spaces,
|
86
|
-
:space => make_spaces,
|
87
|
-
:space_before => make_spaces,
|
88
|
-
:object_nl => make_spaces,
|
89
|
-
:array_nl => make_spaces
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def make_spaces
|
94
|
-
s = ''
|
95
|
-
rand(1).times { s << WS[rand(WS.size)] }
|
96
|
-
s
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
n = (ARGV.shift || 500).to_i
|
101
|
-
loop do
|
102
|
-
fuzzer = Fuzzer.new(n,
|
103
|
-
Hash => 25,
|
104
|
-
Array => 25,
|
105
|
-
String => 10,
|
106
|
-
Fixnum => 10,
|
107
|
-
Bignum => 10,
|
108
|
-
nil => 5,
|
109
|
-
true => 5,
|
110
|
-
false => 5
|
111
|
-
)
|
112
|
-
o1 = fuzzer.fuzz
|
113
|
-
json = JSON.generate o1, MyState.new
|
114
|
-
if $DEBUG
|
115
|
-
puts "-" * 80
|
116
|
-
puts json, json.size
|
117
|
-
else
|
118
|
-
puts json.size
|
119
|
-
end
|
120
|
-
begin
|
121
|
-
o2 = JSON.parse(json)
|
122
|
-
rescue JSON::ParserError => e
|
123
|
-
puts "Caught #{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
|
124
|
-
puts "o1 = #{o1.inspect}", "json = #{json}", "json_str = #{json.inspect}"
|
125
|
-
puts "locals = #{local_variables.inspect}"
|
126
|
-
exit
|
127
|
-
end
|
128
|
-
if o1 != o2
|
129
|
-
puts "mismatch", "o1 = #{o1.inspect}", "o2 = #{o2.inspect}",
|
130
|
-
"json = #{json}", "json_str = #{json.inspect}"
|
131
|
-
puts "locals = #{local_variables.inspect}"
|
132
|
-
end
|
133
|
-
end
|
data/tools/server.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$KCODE='UTF8'
|
4
|
-
require 'webrick'
|
5
|
-
include WEBrick
|
6
|
-
$:.unshift 'ext'
|
7
|
-
$:.unshift 'lib'
|
8
|
-
require 'json'
|
9
|
-
|
10
|
-
class JSONServlet < HTTPServlet::AbstractServlet
|
11
|
-
@@count = 1
|
12
|
-
|
13
|
-
def do_GET(req, res)
|
14
|
-
obj = {
|
15
|
-
"TIME" => Time.now.strftime("%FT%T"),
|
16
|
-
"foo" => "Bär",
|
17
|
-
"bar" => "© ≠ €!",
|
18
|
-
'a' => 2,
|
19
|
-
'b' => 3.141,
|
20
|
-
'COUNT' => @@count += 1,
|
21
|
-
'c' => 'c',
|
22
|
-
'd' => [ 1, "b", 3.14 ],
|
23
|
-
'e' => { 'foo' => 'bar' },
|
24
|
-
'g' => "松本行弘",
|
25
|
-
'h' => 1000.0,
|
26
|
-
'i' => 0.001,
|
27
|
-
'j' => "\xf0\xa0\x80\x81",
|
28
|
-
}
|
29
|
-
res.body = JSON.generate obj
|
30
|
-
res['Content-Type'] = "application/json"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_server(err, dir, port)
|
35
|
-
dir = File.expand_path(dir)
|
36
|
-
err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"
|
37
|
-
|
38
|
-
s = HTTPServer.new(
|
39
|
-
:Port => port,
|
40
|
-
:DocumentRoot => dir,
|
41
|
-
:Logger => WEBrick::Log.new(err),
|
42
|
-
:AccessLog => [
|
43
|
-
[ err, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
44
|
-
[ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
|
45
|
-
[ err, WEBrick::AccessLog::AGENT_LOG_FORMAT ]
|
46
|
-
]
|
47
|
-
)
|
48
|
-
s.mount("/json", JSONServlet)
|
49
|
-
s
|
50
|
-
end
|
51
|
-
|
52
|
-
default_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
|
53
|
-
dir = ARGV.shift || default_dir
|
54
|
-
port = (ARGV.shift || 6666).to_i
|
55
|
-
s = create_server(STDERR, dir, 6666)
|
56
|
-
t = Thread.new { s.start }
|
57
|
-
trap(:INT) do
|
58
|
-
s.shutdown
|
59
|
-
t.join
|
60
|
-
exit
|
61
|
-
end
|
62
|
-
sleep
|