json 1.0.3-mswin32

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.

Files changed (84) hide show
  1. data/CHANGES +32 -0
  2. data/GPL +340 -0
  3. data/README +77 -0
  4. data/Rakefile +304 -0
  5. data/TODO +1 -0
  6. data/VERSION +1 -0
  7. data/benchmarks/benchmark.txt +133 -0
  8. data/benchmarks/benchmark_generator.rb +44 -0
  9. data/benchmarks/benchmark_parser.rb +22 -0
  10. data/benchmarks/benchmark_rails.rb +26 -0
  11. data/bin/edit_json.rb +11 -0
  12. data/bin/prettify_json.rb +75 -0
  13. data/data/example.json +1 -0
  14. data/data/index.html +37 -0
  15. data/data/prototype.js +2515 -0
  16. data/ext/json/ext/generator.so +0 -0
  17. data/ext/json/ext/generator/extconf.rb +9 -0
  18. data/ext/json/ext/generator/generator.c +729 -0
  19. data/ext/json/ext/generator/unicode.c +184 -0
  20. data/ext/json/ext/generator/unicode.h +40 -0
  21. data/ext/json/ext/parser.so +0 -0
  22. data/ext/json/ext/parser/extconf.rb +9 -0
  23. data/ext/json/ext/parser/parser.c +1554 -0
  24. data/ext/json/ext/parser/parser.rl +515 -0
  25. data/ext/json/ext/parser/unicode.c +156 -0
  26. data/ext/json/ext/parser/unicode.h +44 -0
  27. data/install.rb +26 -0
  28. data/lib/json.rb +205 -0
  29. data/lib/json/Array.xpm +21 -0
  30. data/lib/json/FalseClass.xpm +21 -0
  31. data/lib/json/Hash.xpm +21 -0
  32. data/lib/json/Key.xpm +73 -0
  33. data/lib/json/NilClass.xpm +21 -0
  34. data/lib/json/Numeric.xpm +28 -0
  35. data/lib/json/String.xpm +96 -0
  36. data/lib/json/TrueClass.xpm +21 -0
  37. data/lib/json/common.rb +184 -0
  38. data/lib/json/editor.rb +1207 -0
  39. data/lib/json/ext.rb +13 -0
  40. data/lib/json/json.xpm +1499 -0
  41. data/lib/json/pure.rb +75 -0
  42. data/lib/json/pure/generator.rb +321 -0
  43. data/lib/json/pure/parser.rb +214 -0
  44. data/lib/json/version.rb +8 -0
  45. data/tests/fixtures/fail1.json +1 -0
  46. data/tests/fixtures/fail10.json +1 -0
  47. data/tests/fixtures/fail11.json +1 -0
  48. data/tests/fixtures/fail12.json +1 -0
  49. data/tests/fixtures/fail13.json +1 -0
  50. data/tests/fixtures/fail14.json +1 -0
  51. data/tests/fixtures/fail15.json +1 -0
  52. data/tests/fixtures/fail16.json +1 -0
  53. data/tests/fixtures/fail17.json +1 -0
  54. data/tests/fixtures/fail19.json +1 -0
  55. data/tests/fixtures/fail2.json +1 -0
  56. data/tests/fixtures/fail20.json +1 -0
  57. data/tests/fixtures/fail21.json +1 -0
  58. data/tests/fixtures/fail22.json +1 -0
  59. data/tests/fixtures/fail23.json +1 -0
  60. data/tests/fixtures/fail24.json +1 -0
  61. data/tests/fixtures/fail25.json +1 -0
  62. data/tests/fixtures/fail26.json +1 -0
  63. data/tests/fixtures/fail27.json +2 -0
  64. data/tests/fixtures/fail28.json +2 -0
  65. data/tests/fixtures/fail3.json +1 -0
  66. data/tests/fixtures/fail4.json +1 -0
  67. data/tests/fixtures/fail5.json +1 -0
  68. data/tests/fixtures/fail6.json +1 -0
  69. data/tests/fixtures/fail7.json +1 -0
  70. data/tests/fixtures/fail8.json +1 -0
  71. data/tests/fixtures/fail9.json +1 -0
  72. data/tests/fixtures/pass1.json +56 -0
  73. data/tests/fixtures/pass18.json +1 -0
  74. data/tests/fixtures/pass2.json +1 -0
  75. data/tests/fixtures/pass3.json +6 -0
  76. data/tests/runner.rb +24 -0
  77. data/tests/test_json.rb +236 -0
  78. data/tests/test_json_addition.rb +94 -0
  79. data/tests/test_json_fixtures.rb +30 -0
  80. data/tests/test_json_generate.rb +81 -0
  81. data/tests/test_json_unicode.rb +58 -0
  82. data/tools/fuzz.rb +131 -0
  83. data/tools/server.rb +62 -0
  84. metadata +149 -0
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'json'
5
+
6
+ class TC_JSONFixtures < Test::Unit::TestCase
7
+ def setup
8
+ $KCODE = 'UTF8'
9
+ fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
10
+ passed, failed = Dir[fixtures].partition { |f| f['pass'] }
11
+ @passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
12
+ @failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
13
+ end
14
+
15
+ def test_passing
16
+ for (name, source) in @passed
17
+ assert JSON.parse(source),
18
+ "Did not pass for fixture '#{name}'"
19
+ end
20
+ end
21
+
22
+ def test_failing
23
+ for (name, source) in @failed
24
+ assert_raises(JSON::ParserError,
25
+ "Did not fail for fixture '#{name}'") do
26
+ JSON.parse(source)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,81 @@
1
+ require 'test/unit'
2
+ require 'json'
3
+
4
+ class TC_JSONGenerate < Test::Unit::TestCase
5
+ include JSON
6
+
7
+ def setup
8
+ $KCODE = 'UTF8'
9
+ @hash = {
10
+ 'a' => 2,
11
+ 'b' => 3.141,
12
+ 'c' => 'c',
13
+ 'd' => [ 1, "b", 3.14 ],
14
+ 'e' => { 'foo' => 'bar' },
15
+ 'g' => "\"\0\037",
16
+ 'h' => 1000.0,
17
+ 'i' => 0.001
18
+ }
19
+ @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
20
+ '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
21
+ @json3 = <<'EOT'.chomp
22
+ {
23
+ "a": 2,
24
+ "b": 3.141,
25
+ "c": "c",
26
+ "d": [
27
+ 1,
28
+ "b",
29
+ 3.14
30
+ ],
31
+ "e": {
32
+ "foo": "bar"
33
+ },
34
+ "g": "\"\u0000\u001f",
35
+ "h": 1000.0,
36
+ "i": 0.001
37
+ }
38
+ EOT
39
+ end
40
+
41
+ def test_unparse
42
+ json = unparse(@hash)
43
+ assert_equal(@json2, json)
44
+ parsed_json = parse(json)
45
+ assert_equal(@hash, parsed_json)
46
+ json = generate({1=>2})
47
+ assert_equal('{"1":2}', json)
48
+ parsed_json = parse(json)
49
+ assert_equal({"1"=>2}, parsed_json)
50
+ end
51
+
52
+ def test_unparse_pretty
53
+ json = pretty_unparse(@hash)
54
+ assert_equal(@json3, json)
55
+ parsed_json = parse(json)
56
+ assert_equal(@hash, parsed_json)
57
+ json = pretty_generate({1=>2})
58
+ assert_equal(<<'EOT'.chomp, json)
59
+ {
60
+ "1": 2
61
+ }
62
+ EOT
63
+ parsed_json = parse(json)
64
+ assert_equal({"1"=>2}, parsed_json)
65
+ end
66
+
67
+ def test_states
68
+ json = generate({1=>2}, nil)
69
+ assert_equal('{"1":2}', json)
70
+ s = JSON.state.new(:check_circular => true)
71
+ #assert s.check_circular
72
+ h = { 1=>2 }
73
+ h[3] = h
74
+ assert_raises(JSON::CircularDatastructure) { generate(h, s) }
75
+ s = JSON.state.new(:check_circular => true)
76
+ #assert s.check_circular
77
+ a = [ 1, 2 ]
78
+ a << a
79
+ assert_raises(JSON::CircularDatastructure) { generate(a, s) }
80
+ end
81
+ end
@@ -0,0 +1,58 @@
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 i == ?\b
45
+ generated = JSON.generate(["" << i])
46
+ assert '["\b"]' == generated || '["\10"]' == generated
47
+ elsif [?\n, ?\r, ?\t, ?\f].include?(i)
48
+ assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
49
+ elsif i < 0x20
50
+ assert_equal json, JSON.generate(["" << i])
51
+ end
52
+ end
53
+ assert_raises(JSON::GeneratorError) do
54
+ JSON.generate(["" << 0x80])
55
+ end
56
+ assert_equal "\302\200", JSON.parse('["\u0080"]').first
57
+ end
58
+ end
@@ -0,0 +1,131 @@
1
+ $KCODE='UTF8'
2
+ require 'json'
3
+
4
+ class Fuzzer
5
+ def initialize(n, freqs = {})
6
+ sum = freqs.inject(0.0) { |s, x| s + x.last }
7
+ freqs.each_key { |x| freqs[x] /= sum }
8
+ s = 0.0
9
+ freqs.each_key do |x|
10
+ freqs[x] = s .. (s + t = freqs[x])
11
+ s += t
12
+ end
13
+ @freqs = freqs
14
+ @n = n
15
+ @alpha = (0..0x7f).to_a
16
+ end
17
+
18
+ def random_string
19
+ s = ''
20
+ 30.times { s << @alpha[rand(@alpha.size)] }
21
+ s
22
+ end
23
+
24
+ def pick
25
+ r = rand
26
+ found = @freqs.find { |k, f| f.include? rand }
27
+ found && found.first
28
+ end
29
+
30
+ def make_pick
31
+ k = pick
32
+ case
33
+ when k == Hash, k == Array
34
+ k.new
35
+ when k == true, k == false, k == nil
36
+ k
37
+ when k == String
38
+ random_string
39
+ when k == Fixnum
40
+ rand(2 ** 30) - 2 ** 29
41
+ when k == Bignum
42
+ rand(2 ** 70) - 2 ** 69
43
+ end
44
+ end
45
+
46
+ def fuzz(current = nil)
47
+ if @n > 0
48
+ case current
49
+ when nil
50
+ @n -= 1
51
+ current = fuzz [ Hash, Array ][rand(2)].new
52
+ when Array
53
+ while @n > 0
54
+ @n -= 1
55
+ current << case p = make_pick
56
+ when Array, Hash
57
+ fuzz(p)
58
+ else
59
+ p
60
+ end
61
+ end
62
+ when Hash
63
+ while @n > 0
64
+ @n -= 1
65
+ current[random_string] = case p = make_pick
66
+ when Array, Hash
67
+ fuzz(p)
68
+ else
69
+ p
70
+ end
71
+ end
72
+ end
73
+ end
74
+ current
75
+ end
76
+ end
77
+
78
+ class MyState < JSON.state
79
+ WS = " \r\t\n"
80
+
81
+ def initialize
82
+ super(
83
+ :indent => make_spaces,
84
+ :space => make_spaces,
85
+ :space_before => make_spaces,
86
+ :object_nl => make_spaces,
87
+ :array_nl => make_spaces
88
+ )
89
+ end
90
+
91
+ def make_spaces
92
+ s = ''
93
+ rand(1).times { s << WS[rand(WS.size)] }
94
+ s
95
+ end
96
+ end
97
+
98
+ n = (ARGV.shift || 500).to_i
99
+ loop do
100
+ fuzzer = Fuzzer.new(n,
101
+ Hash => 25,
102
+ Array => 25,
103
+ String => 10,
104
+ Fixnum => 10,
105
+ Bignum => 10,
106
+ nil => 5,
107
+ true => 5,
108
+ false => 5
109
+ )
110
+ o1 = fuzzer.fuzz
111
+ json = JSON.generate o1, MyState.new
112
+ if $DEBUG
113
+ puts "-" * 80
114
+ puts json, json.size
115
+ else
116
+ puts json.size
117
+ end
118
+ begin
119
+ o2 = JSON.parse(json)
120
+ rescue JSON::ParserError => e
121
+ puts "Caught #{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
122
+ puts "o1 = #{o1.inspect}", "json = #{json}", "json_str = #{json.inspect}"
123
+ puts "locals = #{local_variables.inspect}"
124
+ exit
125
+ end
126
+ if o1 != o2
127
+ puts "mismatch", "o1 = #{o1.inspect}", "o2 = #{o2.inspect}",
128
+ "json = #{json}", "json_str = #{json.inspect}"
129
+ puts "locals = #{local_variables.inspect}"
130
+ end
131
+ end
@@ -0,0 +1,62 @@
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
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: json
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.3
7
+ date: 2007-04-27 00:00:00 +02:00
8
+ summary: A JSON implementation as a Ruby extension
9
+ require_paths:
10
+ - ext/json/ext
11
+ - ext
12
+ - lib
13
+ email: flori@ping.de
14
+ homepage: http://json.rubyforge.org
15
+ rubyforge_project: json
16
+ description: ""
17
+ autorequire:
18
+ default_executable: edit_json.rb
19
+ bindir: bin
20
+ has_rdoc: true
21
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
22
+ requirements:
23
+ - - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
27
+ platform: mswin32
28
+ signing_key:
29
+ cert_chain:
30
+ post_install_message:
31
+ authors:
32
+ - Florian Frank
33
+ files:
34
+ - bin
35
+ - bin/edit_json.rb
36
+ - bin/prettify_json.rb
37
+ - VERSION
38
+ - TODO
39
+ - tests
40
+ - tests/test_json_fixtures.rb
41
+ - tests/runner.rb
42
+ - tests/test_json.rb
43
+ - tests/fixtures
44
+ - tests/fixtures/fail27.json
45
+ - tests/fixtures/fail22.json
46
+ - tests/fixtures/fail26.json
47
+ - tests/fixtures/fail16.json
48
+ - tests/fixtures/fail28.json
49
+ - tests/fixtures/fail25.json
50
+ - tests/fixtures/pass18.json
51
+ - tests/fixtures/fail9.json
52
+ - tests/fixtures/fail20.json
53
+ - tests/fixtures/fail24.json
54
+ - tests/fixtures/fail14.json
55
+ - tests/fixtures/fail4.json
56
+ - tests/fixtures/fail7.json
57
+ - tests/fixtures/fail10.json
58
+ - tests/fixtures/fail13.json
59
+ - tests/fixtures/fail6.json
60
+ - tests/fixtures/fail21.json
61
+ - tests/fixtures/fail23.json
62
+ - tests/fixtures/fail3.json
63
+ - tests/fixtures/fail1.json
64
+ - tests/fixtures/fail11.json
65
+ - tests/fixtures/fail5.json
66
+ - tests/fixtures/pass1.json
67
+ - tests/fixtures/fail12.json
68
+ - tests/fixtures/fail15.json
69
+ - tests/fixtures/pass3.json
70
+ - tests/fixtures/fail8.json
71
+ - tests/fixtures/fail17.json
72
+ - tests/fixtures/fail19.json
73
+ - tests/fixtures/pass2.json
74
+ - tests/fixtures/fail2.json
75
+ - tests/test_json_unicode.rb
76
+ - tests/test_json_generate.rb
77
+ - tests/test_json_addition.rb
78
+ - GPL
79
+ - install.rb
80
+ - ext
81
+ - ext/json
82
+ - ext/json/ext
83
+ - ext/json/ext/generator
84
+ - ext/json/ext/generator/unicode.c
85
+ - ext/json/ext/generator/unicode.h
86
+ - ext/json/ext/generator/extconf.rb
87
+ - ext/json/ext/generator/generator.c
88
+ - ext/json/ext/parser
89
+ - ext/json/ext/parser/parser.c
90
+ - ext/json/ext/parser/unicode.c
91
+ - ext/json/ext/parser/parser.rl
92
+ - ext/json/ext/parser/unicode.h
93
+ - ext/json/ext/parser/extconf.rb
94
+ - diagrams
95
+ - benchmarks
96
+ - benchmarks/benchmark_generator.rb
97
+ - benchmarks/benchmark.txt
98
+ - benchmarks/benchmark_parser.rb
99
+ - benchmarks/benchmark_rails.rb
100
+ - Rakefile
101
+ - data
102
+ - data/example.json
103
+ - data/prototype.js
104
+ - data/index.html
105
+ - lib
106
+ - lib/json
107
+ - lib/json/FalseClass.xpm
108
+ - lib/json/TrueClass.xpm
109
+ - lib/json/ext.rb
110
+ - lib/json/common.rb
111
+ - lib/json/Hash.xpm
112
+ - lib/json/pure
113
+ - lib/json/pure/parser.rb
114
+ - lib/json/pure/generator.rb
115
+ - lib/json/Key.xpm
116
+ - lib/json/Numeric.xpm
117
+ - lib/json/Array.xpm
118
+ - lib/json/editor.rb
119
+ - lib/json/String.xpm
120
+ - lib/json/pure.rb
121
+ - lib/json/NilClass.xpm
122
+ - lib/json/version.rb
123
+ - lib/json/json.xpm
124
+ - lib/json.rb
125
+ - README
126
+ - tools
127
+ - tools/server.rb
128
+ - tools/fuzz.rb
129
+ - CHANGES
130
+ - ext/json/ext/parser.so
131
+ - ext/json/ext/generator.so
132
+ test_files:
133
+ - tests/runner.rb
134
+ rdoc_options:
135
+ - --title
136
+ - JSON -- A JSON implemention
137
+ - --main
138
+ - JSON
139
+ - --line-numbers
140
+ extra_rdoc_files: []
141
+
142
+ executables:
143
+ - edit_json.rb
144
+ extensions: []
145
+
146
+ requirements: []
147
+
148
+ dependencies: []
149
+