json 1.1.1 → 1.1.2

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.

@@ -58,6 +58,9 @@ module JSON
58
58
  # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
59
59
  # defiance of RFC 4627 to be parsed by the Parser. This option defaults
60
60
  # to false.
61
+ # * *create_additions*: If set to false, the Parser doesn't create
62
+ # additions even if a matchin class and create_id was found. This option
63
+ # defaults to true.
61
64
  def initialize(source, opts = {})
62
65
  super
63
66
  if !opts.key?(:max_nesting) # defaults to 19
@@ -68,7 +71,9 @@ module JSON
68
71
  @max_nesting = 0
69
72
  end
70
73
  @allow_nan = !!opts[:allow_nan]
71
- @create_id = JSON.create_id
74
+ ca = true
75
+ ca = opts[:create_additions] if opts.key?(:create_additions)
76
+ @create_id = ca ? JSON.create_id : nil
72
77
  end
73
78
 
74
79
  alias source string
@@ -235,11 +240,10 @@ module JSON
235
240
  if delim
236
241
  raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
237
242
  end
238
- if klassname = result[@create_id]
243
+ if @create_id and klassname = result[@create_id]
239
244
  klass = JSON.deep_const_get klassname
240
245
  break unless klass and klass.json_creatable?
241
246
  result = klass.json_create(result)
242
- result
243
247
  end
244
248
  break
245
249
  when skip(IGNORE)
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
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:
@@ -8,6 +8,7 @@ require 'test_json'
8
8
  require 'test_json_generate'
9
9
  require 'test_json_unicode'
10
10
  require 'test_json_addition'
11
+ require 'test_json_rails'
11
12
  require 'test_json_fixtures'
12
13
 
13
14
  class TS_AllTests
@@ -17,6 +18,7 @@ class TS_AllTests
17
18
  suite << TC_JSON.suite
18
19
  suite << TC_JSONUnicode.suite
19
20
  suite << TC_JSONAddition.suite
21
+ suite << TC_JSONRails.suite
20
22
  suite << TC_JSONFixtures.suite
21
23
  end
22
24
  end
@@ -39,6 +39,10 @@ class TC_JSONAddition < Test::Unit::TestCase
39
39
  end
40
40
 
41
41
  class C
42
+ def self.json_creatable?
43
+ false
44
+ end
45
+
42
46
  def to_json(*args)
43
47
  {
44
48
  'json_class' => 'TC_JSONAddition::Nix',
@@ -59,6 +63,21 @@ class TC_JSONAddition < Test::Unit::TestCase
59
63
  assert_equal a, a_again
60
64
  end
61
65
 
66
+ def test_extended_json_disabled
67
+ a = A.new(666)
68
+ assert A.json_creatable?
69
+ json = generate(a)
70
+ a_again = JSON.parse(json, :create_additions => true)
71
+ assert_kind_of a.class, a_again
72
+ assert_equal a, a_again
73
+ a_hash = JSON.parse(json, :create_additions => false)
74
+ assert_kind_of Hash, a_hash
75
+ assert_equal(
76
+ {"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
77
+ a_hash.sort_by { |k,| k }
78
+ )
79
+ end
80
+
62
81
  def test_extended_json_fail
63
82
  b = B.new
64
83
  assert !B.json_creatable?
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'json/add/rails'
5
+ require 'date'
6
+
7
+ class TC_JSONRails < Test::Unit::TestCase
8
+ include JSON
9
+
10
+ class A
11
+ def initialize(a)
12
+ @a = a
13
+ end
14
+
15
+ attr_reader :a
16
+
17
+ def ==(other)
18
+ a == other.a
19
+ end
20
+
21
+ def self.json_create(object)
22
+ new(*object['args'])
23
+ end
24
+
25
+ def to_json(*args)
26
+ {
27
+ 'json_class' => self.class.name,
28
+ 'args' => [ @a ],
29
+ }.to_json(*args)
30
+ end
31
+ end
32
+
33
+ class B
34
+ def to_json(*args)
35
+ {
36
+ 'json_class' => self.class.name,
37
+ }.to_json(*args)
38
+ end
39
+ end
40
+
41
+ class C
42
+ def to_json(*args)
43
+ {
44
+ 'json_class' => 'TC_JSONRails::Nix',
45
+ }.to_json(*args)
46
+ end
47
+ end
48
+
49
+ def setup
50
+ $KCODE = 'UTF8'
51
+ end
52
+
53
+ def test_extended_json
54
+ a = A.new(666)
55
+ assert A.json_creatable?
56
+ json = generate(a)
57
+ a_again = JSON.parse(json)
58
+ assert_kind_of a.class, a_again
59
+ assert_equal a, a_again
60
+ end
61
+
62
+ def test_extended_json_disabled
63
+ a = A.new(666)
64
+ assert A.json_creatable?
65
+ json = generate(a)
66
+ a_again = JSON.parse(json, :create_additions => true)
67
+ assert_kind_of a.class, a_again
68
+ assert_equal a, a_again
69
+ a_hash = JSON.parse(json, :create_additions => false)
70
+ assert_kind_of Hash, a_hash
71
+ assert_equal(
72
+ {"args"=>[666], "json_class"=>"TC_JSONRails::A"}.sort_by { |k,| k },
73
+ a_hash.sort_by { |k,| k }
74
+ )
75
+ end
76
+
77
+ def test_extended_json_fail
78
+ b = B.new
79
+ assert !B.json_creatable?
80
+ json = generate(b)
81
+ assert_equal({ 'json_class' => B.name }, JSON.parse(json))
82
+ end
83
+
84
+ def test_extended_json_fail
85
+ c = C.new # with rails addition all objects are theoretically creatable
86
+ assert C.json_creatable?
87
+ json = generate(c)
88
+ assert_raises(ArgumentError) { JSON.parse(json) }
89
+ end
90
+
91
+ def test_raw_strings
92
+ raw = ''
93
+ raw_array = []
94
+ for i in 0..255
95
+ raw << i
96
+ raw_array << i
97
+ end
98
+ json = raw.to_json_raw
99
+ json_raw_object = raw.to_json_raw_object
100
+ hash = { 'json_class' => 'String', 'raw'=> raw_array }
101
+ assert_equal hash, json_raw_object
102
+ json_raw = <<EOT.chomp
103
+ {\"json_class\":\"String\",\"raw\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255]}
104
+ EOT
105
+ # "
106
+ assert_equal json_raw, json
107
+ raw_again = JSON.parse(json)
108
+ assert_equal raw, raw_again
109
+ end
110
+
111
+ def test_symbol
112
+ assert_equal '"foo"', JSON(:foo) # we don't want an object here
113
+ end
114
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: json
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2007-07-06 00:00:00 +02:00
6
+ version: 1.1.2
7
+ date: 2007-11-27 00:00:00 +01:00
8
8
  summary: A JSON implementation as a Ruby extension
9
9
  require_paths:
10
10
  - ext/json/ext
@@ -27,109 +27,111 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
27
27
  platform: ruby
28
28
  signing_key:
29
29
  cert_chain:
30
+ post_install_message:
30
31
  authors:
31
32
  - Florian Frank
32
33
  files:
33
- - bin
34
- - VERSION
35
- - TODO
36
- - tests
37
- - RUBY
38
- - GPL
39
34
  - install.rb
40
- - ext
41
- - diagrams
42
- - benchmarks
43
- - Rakefile
44
- - data
45
35
  - lib
36
+ - lib/json.rb
37
+ - lib/json
38
+ - lib/json/Array.xpm
39
+ - lib/json/FalseClass.xpm
40
+ - lib/json/json.xpm
41
+ - lib/json/editor.rb
42
+ - lib/json/Hash.xpm
43
+ - lib/json/Key.xpm
44
+ - lib/json/common.rb
45
+ - lib/json/String.xpm
46
+ - lib/json/pure
47
+ - lib/json/pure/generator.rb
48
+ - lib/json/pure/parser.rb
49
+ - lib/json/Numeric.xpm
50
+ - lib/json/ext.rb
51
+ - lib/json/pure.rb
52
+ - lib/json/NilClass.xpm
53
+ - lib/json/add
54
+ - lib/json/add/rails.rb
55
+ - lib/json/add/core.rb
56
+ - lib/json/TrueClass.xpm
57
+ - lib/json/version.rb
58
+ - ext
59
+ - ext/json
60
+ - ext/json/ext
61
+ - ext/json/ext/parser
62
+ - ext/json/ext/parser/unicode.h
63
+ - ext/json/ext/parser/parser.c
64
+ - ext/json/ext/parser/extconf.rb
65
+ - ext/json/ext/parser/unicode.c
66
+ - ext/json/ext/parser/parser.rl
67
+ - ext/json/ext/generator
68
+ - ext/json/ext/generator/unicode.h
69
+ - ext/json/ext/generator/extconf.rb
70
+ - ext/json/ext/generator/generator.c
71
+ - ext/json/ext/generator/unicode.c
46
72
  - README
47
- - tools
73
+ - diagrams
48
74
  - CHANGES
49
- - bin/edit_json.rb
50
- - bin/prettify_json.rb
51
- - tests/test_json_fixtures.rb
52
- - tests/runner.rb
75
+ - RUBY
76
+ - TODO
77
+ - VERSION
78
+ - tests
53
79
  - tests/test_json.rb
54
- - tests/fixtures
55
- - tests/test_json_unicode.rb
56
- - tests/test_json_generate.rb
57
80
  - tests/test_json_addition.rb
58
- - tests/fixtures/fail27.json
59
- - tests/fixtures/pass26.json
60
- - tests/fixtures/fail22.json
61
- - tests/fixtures/pass17.json
62
- - tests/fixtures/fail28.json
63
- - tests/fixtures/fail25.json
64
- - tests/fixtures/fail9.json
65
- - tests/fixtures/fail20.json
66
- - tests/fixtures/fail24.json
67
- - tests/fixtures/fail14.json
68
- - tests/fixtures/fail4.json
69
- - tests/fixtures/fail7.json
81
+ - tests/fixtures
82
+ - tests/fixtures/fail11.json
83
+ - tests/fixtures/fail5.json
70
84
  - tests/fixtures/fail10.json
85
+ - tests/fixtures/fail3.json
71
86
  - tests/fixtures/pass15.json
72
- - tests/fixtures/fail18.json
73
- - tests/fixtures/fail13.json
87
+ - tests/fixtures/fail9.json
88
+ - tests/fixtures/fail22.json
74
89
  - tests/fixtures/fail6.json
75
- - tests/fixtures/fail21.json
76
- - tests/fixtures/fail23.json
77
- - tests/fixtures/fail3.json
90
+ - tests/fixtures/pass2.json
91
+ - tests/fixtures/fail20.json
92
+ - tests/fixtures/fail19.json
93
+ - tests/fixtures/fail12.json
94
+ - tests/fixtures/fail7.json
95
+ - tests/fixtures/fail4.json
78
96
  - tests/fixtures/fail1.json
79
- - tests/fixtures/fail11.json
80
- - tests/fixtures/fail5.json
97
+ - tests/fixtures/fail24.json
98
+ - tests/fixtures/fail21.json
81
99
  - tests/fixtures/pass1.json
82
- - tests/fixtures/fail12.json
100
+ - tests/fixtures/fail2.json
101
+ - tests/fixtures/fail25.json
102
+ - tests/fixtures/pass16.json
83
103
  - tests/fixtures/pass3.json
104
+ - tests/fixtures/fail18.json
105
+ - tests/fixtures/fail28.json
106
+ - tests/fixtures/fail13.json
107
+ - tests/fixtures/fail27.json
108
+ - tests/fixtures/pass17.json
109
+ - tests/fixtures/pass26.json
110
+ - tests/fixtures/fail23.json
111
+ - tests/fixtures/fail14.json
84
112
  - tests/fixtures/fail8.json
85
- - tests/fixtures/fail19.json
86
- - tests/fixtures/pass16.json
87
- - tests/fixtures/pass2.json
88
- - tests/fixtures/fail2.json
89
- - ext/json
90
- - ext/json/ext
91
- - ext/json/ext/generator
92
- - ext/json/ext/parser
93
- - ext/json/ext/generator/unicode.c
94
- - ext/json/ext/generator/unicode.h
95
- - ext/json/ext/generator/extconf.rb
96
- - ext/json/ext/generator/generator.c
97
- - ext/json/ext/parser/unicode.c
98
- - ext/json/ext/parser/parser.rl
99
- - ext/json/ext/parser/unicode.h
100
- - ext/json/ext/parser/extconf.rb
101
- - benchmarks/benchmark_generator.rb
102
- - benchmarks/benchmark.txt
113
+ - tests/runner.rb
114
+ - tests/test_json_generate.rb
115
+ - tests/test_json_rails.rb
116
+ - tests/test_json_unicode.rb
117
+ - tests/test_json_fixtures.rb
118
+ - benchmarks
103
119
  - benchmarks/benchmark_parser.rb
120
+ - benchmarks/benchmark_generator.rb
104
121
  - benchmarks/benchmark_rails.rb
122
+ - benchmarks/benchmark.txt
123
+ - Rakefile
124
+ - GPL
125
+ - data
105
126
  - data/example.json
106
- - data/prototype.js
107
127
  - data/index.html
108
- - lib/json
109
- - lib/json.rb
110
- - lib/json/FalseClass.xpm
111
- - lib/json/TrueClass.xpm
112
- - lib/json/add
113
- - lib/json/ext.rb
114
- - lib/json/common.rb
115
- - lib/json/Hash.xpm
116
- - lib/json/pure
117
- - lib/json/Key.xpm
118
- - lib/json/Numeric.xpm
119
- - lib/json/Array.xpm
120
- - lib/json/editor.rb
121
- - lib/json/String.xpm
122
- - lib/json/pure.rb
123
- - lib/json/NilClass.xpm
124
- - lib/json/version.rb
125
- - lib/json/json.xpm
126
- - lib/json/add/core.rb
127
- - lib/json/add/rails.rb
128
- - lib/json/pure/parser.rb
129
- - lib/json/pure/generator.rb
130
- - tools/server.rb
128
+ - data/prototype.js
129
+ - bin
130
+ - bin/edit_json.rb
131
+ - bin/prettify_json.rb
132
+ - tools
131
133
  - tools/fuzz.rb
132
- - ext/json/ext/parser/parser.c
134
+ - tools/server.rb
133
135
  test_files:
134
136
  - tests/runner.rb
135
137
  rdoc_options: