json_pure 2.0.4 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -5
  4. data/CHANGES.md +39 -0
  5. data/Gemfile +1 -3
  6. data/LICENSE +56 -0
  7. data/README.md +54 -21
  8. data/Rakefile +19 -93
  9. data/VERSION +1 -1
  10. data/ext/json/ext/generator/generator.c +214 -45
  11. data/ext/json/ext/generator/generator.h +5 -2
  12. data/ext/json/ext/parser/extconf.rb +25 -0
  13. data/ext/json/ext/parser/parser.c +155 -83
  14. data/ext/json/ext/parser/parser.h +2 -0
  15. data/ext/json/ext/parser/parser.rl +79 -7
  16. data/ext/json/extconf.rb +1 -0
  17. data/java/src/json/ext/Generator.java +28 -24
  18. data/java/src/json/ext/GeneratorState.java +30 -0
  19. data/java/src/json/ext/Parser.java +109 -82
  20. data/java/src/json/ext/Parser.rl +39 -12
  21. data/java/src/json/ext/StringEncoder.java +8 -2
  22. data/json-java.gemspec +22 -22
  23. data/json.gemspec +0 -0
  24. data/json_pure.gemspec +9 -14
  25. data/lib/json.rb +549 -29
  26. data/lib/json/add/bigdecimal.rb +2 -2
  27. data/lib/json/add/complex.rb +2 -3
  28. data/lib/json/add/ostruct.rb +1 -1
  29. data/lib/json/add/rational.rb +2 -3
  30. data/lib/json/add/regexp.rb +2 -2
  31. data/lib/json/add/set.rb +29 -0
  32. data/lib/json/common.rb +341 -115
  33. data/lib/json/pure/generator.rb +31 -10
  34. data/lib/json/pure/parser.rb +35 -5
  35. data/lib/json/version.rb +1 -1
  36. data/tests/json_addition_test.rb +6 -0
  37. data/tests/json_common_interface_test.rb +47 -4
  38. data/tests/json_encoding_test.rb +2 -2
  39. data/tests/json_fixtures_test.rb +9 -1
  40. data/tests/json_generator_test.rb +55 -0
  41. data/tests/json_parser_test.rb +43 -12
  42. data/tests/test_helper.rb +3 -7
  43. metadata +17 -13
  44. data/data/example.json +0 -1
  45. data/data/index.html +0 -38
  46. data/data/prototype.js +0 -4184
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b23de3bf1ee0fe28a7c557f8f004ed78008e183f
4
- data.tar.gz: 18c5c1c5311a254df4f512fa33866268185280e4
2
+ SHA256:
3
+ metadata.gz: 19ad55284912f57f06f2aa2d0a6336486ee6d20112a3cec8e3f4e918a0fbd338
4
+ data.tar.gz: 159c717b0b0cc8e4e6d8609b542b113fb8c483e1a306b6582f8a98ddadc20090
5
5
  SHA512:
6
- metadata.gz: e04b89c73f033246890c908deb5af1e51bd066286341e119cfbd2ac1c97727a3d65150b0a39484aead58c02fb8bedd6a378231bc8df2de29edee78351031a798
7
- data.tar.gz: 1a1a9702657ad711e48ee470485c5c6101e30ec05b4df6dd0b9d7d524f16f5f0c722f3b672a19e5a6fe9920c014fcb857f6dcfb416ac657cab91dd3bc228be37
6
+ metadata.gz: fba550423cbfb98dfe9abc4fe534e7fbeff135cde38a0e17b98123dbf8a664b70e7d26e130b536292123268266917251c06800b1224eca3007e1f6f54a148b16
7
+ data.tar.gz: fbe734f8b76e9f4c4c90304d11fa8026d349e2684f01358140cb36113720a57016fbbe8b12857f5e2c7b82baef2ac09a528b7839e17a22f87132940af98da2a0
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ Gemfile.lock
15
15
  */**/Makefile
16
16
  */**/*.o
17
17
  .byebug_history
18
+ *.log
@@ -4,16 +4,20 @@ language: ruby
4
4
 
5
5
  # Specify which ruby versions you wish to run your tests on, each version will be used
6
6
  rvm:
7
- - 1.9.3
8
- - 2.0.0
9
7
  - 2.1
10
8
  - 2.2
11
- - 2.3.3
12
- - 2.4.0
13
- - jruby
9
+ - 2.3
10
+ - 2.4
11
+ - 2.5
12
+ - 2.6
13
+ - 2.7.0-preview3
14
14
  - ruby-head
15
+ - jruby-9.1 # Ruby 2.3
16
+ - jruby-9.2 # Ruby 2.5
17
+ - truffleruby
15
18
  matrix:
16
19
  allow_failures:
17
20
  - rvm: ruby-head
21
+ - rvm: truffleruby
18
22
  script: "bundle exec rake"
19
23
  sudo: false
data/CHANGES.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changes
2
2
 
3
+ ## 2020-06-30 (2.3.1)
4
+
5
+ * Spelling and grammar fixes for comments. Pull request #191 by Josh
6
+ Kline.
7
+ * Enhance generic JSON and #generate docs. Pull request #347 by Victor
8
+ Shepelev.
9
+ * Add :nodoc: for GeneratorMethods. Pull request #349 by Victor Shepelev.
10
+ * Baseline changes to help (JRuby) development. Pull request #371 by Karol
11
+ Bucek.
12
+ * Add metadata for rubygems.org. Pull request #379 by Alexandre ZANNI.
13
+ * Remove invalid JSON.generate description from JSON module rdoc. Pull
14
+ request #384 by Jeremy Evans.
15
+ * Test with TruffleRuby in CI. Pull request #402 by Benoit Daloze.
16
+ * Rdoc enhancements. Pull request #413 by Burdette Lamar.
17
+ * Fixtures/ are not being tested... Pull request #416 by Marc-André
18
+ Lafortune.
19
+ * Use frozen string for hash key. Pull request #420 by Marc-André
20
+ Lafortune.
21
+ * Added :call-seq: to RDoc for some methods. Pull request #422 by Burdette
22
+ Lamar.
23
+ * Small typo fix. Pull request #423 by Marc-André Lafortune.
24
+
25
+ ## 2019-12-11 (2.3.0)
26
+ * Fix default of `create_additions` to always be `false` for `JSON(user_input)`
27
+ and `JSON.parse(user_input, nil)`.
28
+ Note that `JSON.load` remains with default `true` and is meant for internal
29
+ serialization of trusted data. [CVE-2020-10663]
30
+ * Fix passing args all #to_json in json/add/*.
31
+ * Fix encoding issues
32
+ * Fix issues of keyword vs positional parameter
33
+ * Fix JSON::Parser against bigdecimal updates
34
+ * Bug fixes to JRuby port
35
+
36
+ ## 2019-02-21 (2.2.0)
37
+ * Adds support for 2.6 BigDecimal and ruby standard library Set datetype.
38
+
39
+ ## 2017-04-18 (2.1.0)
40
+ * Allow passing of `decimal_class` option to specify a class as which to parse
41
+ JSON float numbers.
3
42
  ## 2017-03-23 (2.0.4)
4
43
  * Raise exception for incomplete unicode surrogates/character escape
5
44
  sequences. This problem was reported by Daniel Gollahon (dgollahon).
data/Gemfile CHANGED
@@ -5,12 +5,10 @@ source 'https://rubygems.org'
5
5
  case ENV['JSON']
6
6
  when 'ext', nil
7
7
  if ENV['RUBY_ENGINE'] == 'jruby'
8
- gemspec :name => 'json', :path => 'java'
8
+ gemspec :name => 'json-java'
9
9
  else
10
10
  gemspec :name => 'json'
11
11
  end
12
12
  when 'pure'
13
13
  gemspec :name => 'json_pure'
14
14
  end
15
-
16
- gem 'simplecov'
data/LICENSE ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- # JSON implementation for Ruby ![Travis Widget]
2
- [Travis Widget]: http://travis-ci.org/flori/json.svg?branch=master
1
+ # JSON implementation for Ruby
2
+
3
+ [![Travis Widget](http://travis-ci.org/flori/json.svg?branch=master)](https://travis-ci.org/flori/json)
3
4
 
4
5
  ## Description
5
6
 
@@ -150,6 +151,18 @@ require 'json/add/rails'
150
151
  Both of the additions attempt to require `'json'` (like above) first, if it has
151
152
  not been required yet.
152
153
 
154
+ ## Serializing exceptions
155
+
156
+ The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
157
+ object to JSON, it will by default only include the exception message.
158
+
159
+ To include the full details, you must either load the `json/add/core` mentioned
160
+ above, or specifically load the exception addition:
161
+
162
+ ```ruby
163
+ require 'json/add/exception'
164
+ ```
165
+
153
166
  ## More Examples
154
167
 
155
168
  To create a JSON document from a ruby data structure, you can call
@@ -179,14 +192,14 @@ should return a JSON object (a hash converted to JSON with `#to_json`) like
179
192
  this (don't forget the `*a` for all the arguments):
180
193
 
181
194
  ```ruby
182
- class Range
183
- def to_json(*a)
184
- {
185
- 'json_class' => self.class.name, # = 'Range'
186
- 'data' => [ first, last, exclude_end? ]
187
- }.to_json(*a)
188
- end
189
- end
195
+ class Range
196
+ def to_json(*a)
197
+ {
198
+ 'json_class' => self.class.name, # = 'Range'
199
+ 'data' => [ first, last, exclude_end? ]
200
+ }.to_json(*a)
201
+ end
202
+ end
190
203
  ```
191
204
 
192
205
  The hash key `json_class` is the class, that will be asked to deserialise the
@@ -194,26 +207,30 @@ JSON representation later. In this case it's `Range`, but any namespace of
194
207
  the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
195
208
  used to store the necessary data to configure the object to be deserialised.
196
209
 
197
- If a the key `json_class` is found in a JSON object, the JSON parser checks
210
+ If the key `json_class` is found in a JSON object, the JSON parser checks
198
211
  if the given class responds to the `json_create` class method. If so, it is
199
212
  called with the JSON object converted to a Ruby hash. So a range can
200
213
  be deserialised by implementing `Range.json_create` like this:
201
214
 
202
215
  ```ruby
203
- class Range
204
- def self.json_create(o)
205
- new(*o['data'])
206
- end
207
- end
216
+ class Range
217
+ def self.json_create(o)
218
+ new(*o['data'])
219
+ end
220
+ end
208
221
  ```
209
222
 
210
223
  Now it possible to serialise/deserialise ranges as well:
211
224
 
212
225
  ```ruby
213
- json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
214
- # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
215
- JSON.parse json
216
- # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
226
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
227
+ # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
228
+ JSON.parse json
229
+ # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
230
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
231
+ # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
232
+ JSON.parse json, :create_additions => true
233
+ # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
217
234
  ```
218
235
 
219
236
  `JSON.generate` always creates the shortest possible string representation of a
@@ -373,6 +390,22 @@ Here are the median comparisons for completeness' sake:
373
390
  secs/call
374
391
  ```
375
392
 
393
+ ## Development
394
+
395
+ ### Release
396
+
397
+ Update the json.gemspec and json-java.gemspec.
398
+
399
+ ```
400
+ rbenv shell 2.6.5
401
+ rake build
402
+ gem push pkg/json-2.3.0.gem
403
+
404
+ rbenv shell jruby-9.2.9.0
405
+ rake build
406
+ gem push pkg/json-2.3.0-java.gem
407
+ ```
408
+
376
409
  ## Author
377
410
 
378
411
  Florian Frank <mailto:flori@ping.de>
@@ -389,4 +422,4 @@ The latest version of this library can be downloaded at
389
422
 
390
423
  Online Documentation should be located at
391
424
 
392
- * http://json.rubyforge.org
425
+ * https://www.rubydoc.info/gems/json
data/Rakefile CHANGED
@@ -23,8 +23,13 @@ class UndocumentedTestTask < Rake::TestTask
23
23
  def desc(*) end
24
24
  end
25
25
 
26
- MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') }
27
- BUNDLE = ENV['BUNDLE'] || %w[bundle].find { |c| system(c, '-v') }
26
+ which = lambda { |c|
27
+ w = `which #{c}`
28
+ break w.chomp unless w.empty?
29
+ }
30
+
31
+ MAKE = ENV['MAKE'] || %w[gmake make].find(&which)
32
+ BUNDLE = ENV['BUNDLE'] || %w[bundle].find(&which)
28
33
  PKG_NAME = 'json'
29
34
  PKG_TITLE = 'JSON Implementation for Ruby'
30
35
  PKG_VERSION = File.read('VERSION').chomp
@@ -47,8 +52,8 @@ JAVA_CLASSES = []
47
52
  JRUBY_PARSER_JAR = File.expand_path("lib/json/ext/parser.jar")
48
53
  JRUBY_GENERATOR_JAR = File.expand_path("lib/json/ext/generator.jar")
49
54
 
50
- RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find { |c| system(c, '-v') }
51
- RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find { |c| system(c, '-v') }
55
+ RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find(&which)
56
+ RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find(&which)
52
57
 
53
58
  desc "Installing library (pure)"
54
59
  task :install_pure => :version do
@@ -73,86 +78,6 @@ task :install_ext => [ :compile, :install_pure, :install_ext_really ]
73
78
  desc "Installing library (extension)"
74
79
  task :install => :install_ext
75
80
 
76
- if defined?(Gem) and defined?(Gem::PackageTask)
77
- spec_pure = Gem::Specification.new do |s|
78
- s.name = 'json_pure'
79
- s.version = PKG_VERSION
80
- s.summary = PKG_TITLE
81
- s.description = "This is a JSON implementation in pure Ruby."
82
-
83
- s.files = PKG_FILES
84
-
85
- s.require_path = 'lib'
86
- s.add_development_dependency 'rake'
87
- s.add_development_dependency 'test-unit', '~> 2.0'
88
-
89
- s.extra_rdoc_files << 'README.md'
90
- s.rdoc_options <<
91
- '--title' << 'JSON implemention for ruby' << '--main' << 'README.md'
92
- s.test_files.concat Dir['./tests/test_*.rb']
93
-
94
- s.author = "Florian Frank"
95
- s.email = "flori@ping.de"
96
- s.homepage = "http://flori.github.com/#{PKG_NAME}"
97
- s.license = 'Ruby'
98
- s.required_ruby_version = '>= 1.9'
99
- end
100
-
101
- desc 'Creates a json_pure.gemspec file'
102
- task :gemspec_pure => :version do
103
- File.open('json_pure.gemspec', 'w') do |gemspec|
104
- gemspec.write spec_pure.to_ruby
105
- end
106
- end
107
-
108
- Gem::PackageTask.new(spec_pure) do |pkg|
109
- pkg.need_tar = true
110
- pkg.package_files = PKG_FILES
111
- end
112
-
113
- spec_ext = Gem::Specification.new do |s|
114
- s.name = 'json'
115
- s.version = PKG_VERSION
116
- s.summary = PKG_TITLE
117
- s.description = "This is a JSON implementation as a Ruby extension in C."
118
-
119
- s.files = PKG_FILES
120
-
121
- s.extensions = FileList['ext/**/extconf.rb']
122
-
123
- s.require_path = 'lib'
124
- s.add_development_dependency 'rake'
125
- s.add_development_dependency 'test-unit', '~> 2.0'
126
-
127
- s.extra_rdoc_files << 'README.md'
128
- s.rdoc_options <<
129
- '--title' << 'JSON implemention for Ruby' << '--main' << 'README.md'
130
- s.test_files.concat Dir['./tests/test_*.rb']
131
-
132
- s.author = "Florian Frank"
133
- s.email = "flori@ping.de"
134
- s.homepage = "http://flori.github.com/#{PKG_NAME}"
135
- s.license = 'Ruby'
136
- s.required_ruby_version = '>= 1.9'
137
- end
138
-
139
- desc 'Creates a json.gemspec file'
140
- task :gemspec_ext => :version do
141
- File.open('json.gemspec', 'w') do |gemspec|
142
- gemspec.write spec_ext.to_ruby
143
- end
144
- end
145
-
146
- Gem::PackageTask.new(spec_ext) do |pkg|
147
- pkg.need_tar = true
148
- pkg.package_files = PKG_FILES
149
- end
150
-
151
-
152
- desc 'Create all gemspec files'
153
- task :gemspec => [ :gemspec_pure, :gemspec_ext ]
154
- end
155
-
156
81
  desc m = "Writing version information for #{PKG_VERSION}"
157
82
  task :version do
158
83
  puts m
@@ -176,7 +101,8 @@ task :check_env do
176
101
  end
177
102
 
178
103
  desc "Testing library (pure ruby)"
179
- task :test_pure => [ :clean, :check_env, :do_test_pure ]
104
+ task :test_pure => [ :set_env_pure, :check_env, :do_test_pure ]
105
+ task(:set_env_pure) { ENV['JSON'] = 'pure' }
180
106
 
181
107
  UndocumentedTestTask.new do |t|
182
108
  t.name = 'do_test_pure'
@@ -187,10 +113,7 @@ UndocumentedTestTask.new do |t|
187
113
  end
188
114
 
189
115
  desc "Testing library (pure ruby and extension)"
190
- task :test do
191
- sh "env JSON=pure #{BUNDLE} exec rake test_pure" or exit 1
192
- sh "env JSON=ext #{BUNDLE} exec rake test_ext" or exit 1
193
- end
116
+ task :test => [ :test_pure, :test_ext ]
194
117
 
195
118
  namespace :gems do
196
119
  desc 'Install all development gems'
@@ -238,7 +161,7 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
238
161
  classpath = (Dir['java/lib/*.jar'] << 'java/src' << JRUBY_JAR) * ':'
239
162
  obj = src.sub(/\.java\Z/, '.class')
240
163
  file obj => src do
241
- sh 'javac', '-classpath', classpath, '-source', '1.5', '-target', '1.5', src
164
+ sh 'javac', '-classpath', classpath, '-source', '1.6', '-target', '1.6', src
242
165
  end
243
166
  JAVA_CLASSES << obj
244
167
  end
@@ -257,7 +180,8 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
257
180
  end
258
181
 
259
182
  desc "Testing library (jruby)"
260
- task :test_ext => [ :create_jar, :check_env, :do_test_ext ]
183
+ task :test_ext => [ :set_env_ext, :create_jar, :check_env, :do_test_ext ]
184
+ task(:set_env_ext) { ENV['JSON'] = 'ext' }
261
185
 
262
186
  UndocumentedTestTask.new do |t|
263
187
  t.name = 'do_test_ext'
@@ -331,7 +255,7 @@ else
331
255
  end
332
256
 
333
257
  desc "Testing library (extension)"
334
- task :test_ext => [ :compile, :check_env, :do_test_ext ]
258
+ task :test_ext => [ :check_env, :compile, :do_test_ext ]
335
259
 
336
260
  UndocumentedTestTask.new do |t|
337
261
  t.name = 'do_test_ext'
@@ -363,6 +287,8 @@ else
363
287
  end
364
288
  src = File.read("parser.c").gsub(/[ \t]+$/, '')
365
289
  src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};')
290
+ src.gsub!(/0 <= \(\*p\) && \(\*p\) <= 31/, "0 <= (signed char)(*p) && (*p) <= 31")
291
+ src[0, 0] = "/* This file is automatically generated from parser.rl by using ragel */"
366
292
  File.open("parser.c", "w") {|f| f.print src}
367
293
  end
368
294
  end
@@ -405,4 +331,4 @@ else
405
331
  end
406
332
 
407
333
  desc "Compile in the the source directory"
408
- task :default => [ :clean, :gemspec, :test ]
334
+ task :default => [ :clean, :test ]