json 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -5
- data/CHANGES.md +33 -0
- data/README.md +16 -0
- data/Rakefile +8 -87
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +119 -6
- data/ext/json/ext/generator/generator.h +5 -2
- data/ext/json/ext/parser/extconf.rb +25 -0
- data/ext/json/ext/parser/parser.c +99 -71
- data/ext/json/ext/parser/parser.h +1 -0
- data/ext/json/ext/parser/parser.rl +29 -1
- data/ext/json/extconf.rb +1 -0
- data/java/src/json/ext/Generator.java +11 -30
- data/java/src/json/ext/GeneratorState.java +30 -0
- data/java/src/json/ext/Parser.java +85 -73
- data/java/src/json/ext/Parser.rl +14 -2
- data/java/src/json/ext/StringEncoder.java +8 -2
- data/json-java.gemspec +22 -21
- data/json.gemspec +0 -0
- data/json_pure.gemspec +8 -13
- data/lib/json/add/complex.rb +0 -1
- data/lib/json/add/rational.rb +0 -1
- data/lib/json/common.rb +339 -113
- data/lib/json/pure/generator.rb +29 -9
- data/lib/json/pure/parser.rb +22 -4
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +549 -29
- data/tests/json_addition_test.rb +0 -4
- data/tests/json_common_interface_test.rb +43 -0
- data/tests/json_fixtures_test.rb +9 -1
- data/tests/json_generator_test.rb +13 -2
- data/tests/json_parser_test.rb +25 -0
- data/tests/test_helper.rb +3 -3
- metadata +23 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b5241427373f8f03f7faa96afdec132dcb7601f2e9cce4903ce0879c208bc3f
|
4
|
+
data.tar.gz: 7e3e820aae7a8036affec28ce44f4aadeebfd74b4bea85ad2d597eb42e82b745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f403e2c458aa86f820671726a92f4798703240099417a22e5d489d140f53d48559560d6603547f2a0f07aa0595fb383c4b1b2c53e1df1b34e16df2ca4ea480
|
7
|
+
data.tar.gz: 5e0f19fe6c8c086adbe499b85bb49c1b5f14697cb63ed8d7fd96d82e8504806eb0b016f8e2a556ec7eab5443beddc8109d2ef5921bd3ac54eedf45056218924b
|
data/.travis.yml
CHANGED
@@ -4,7 +4,6 @@ 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
|
-
- 2.0.0
|
8
7
|
- 2.1
|
9
8
|
- 2.2
|
10
9
|
- 2.3
|
@@ -13,12 +12,12 @@ rvm:
|
|
13
12
|
- 2.6
|
14
13
|
- 2.7.0-preview3
|
15
14
|
- ruby-head
|
16
|
-
- jruby
|
17
|
-
- jruby-9.2.
|
15
|
+
- jruby-9.1 # Ruby 2.3
|
16
|
+
- jruby-9.2 # Ruby 2.5
|
17
|
+
- truffleruby
|
18
18
|
matrix:
|
19
19
|
allow_failures:
|
20
20
|
- rvm: ruby-head
|
21
|
-
- rvm:
|
22
|
-
- rvm: jruby-9.2.7.0
|
21
|
+
- rvm: truffleruby
|
23
22
|
script: "bundle exec rake"
|
24
23
|
sudo: false
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,38 @@
|
|
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
|
+
|
3
36
|
## 2019-02-21 (2.2.0)
|
4
37
|
* Adds support for 2.6 BigDecimal and ruby standard library Set datetype.
|
5
38
|
|
data/README.md
CHANGED
@@ -390,6 +390,22 @@ Here are the median comparisons for completeness' sake:
|
|
390
390
|
secs/call
|
391
391
|
```
|
392
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
|
+
|
393
409
|
## Author
|
394
410
|
|
395
411
|
Florian Frank <mailto:flori@ping.de>
|
data/Rakefile
CHANGED
@@ -78,86 +78,6 @@ task :install_ext => [ :compile, :install_pure, :install_ext_really ]
|
|
78
78
|
desc "Installing library (extension)"
|
79
79
|
task :install => :install_ext
|
80
80
|
|
81
|
-
if defined?(Gem) and defined?(Gem::PackageTask)
|
82
|
-
spec_pure = Gem::Specification.new do |s|
|
83
|
-
s.name = 'json_pure'
|
84
|
-
s.version = PKG_VERSION
|
85
|
-
s.summary = PKG_TITLE
|
86
|
-
s.description = "This is a JSON implementation in pure Ruby."
|
87
|
-
|
88
|
-
s.files = PKG_FILES
|
89
|
-
|
90
|
-
s.require_path = 'lib'
|
91
|
-
s.add_development_dependency 'rake'
|
92
|
-
s.add_development_dependency 'test-unit', '~> 2.0'
|
93
|
-
|
94
|
-
s.extra_rdoc_files << 'README.md'
|
95
|
-
s.rdoc_options <<
|
96
|
-
'--title' << 'JSON implemention for ruby' << '--main' << 'README.md'
|
97
|
-
s.test_files.concat Dir['./tests/test_*.rb']
|
98
|
-
|
99
|
-
s.author = "Florian Frank"
|
100
|
-
s.email = "flori@ping.de"
|
101
|
-
s.homepage = "http://flori.github.com/#{PKG_NAME}"
|
102
|
-
s.license = 'Ruby'
|
103
|
-
s.required_ruby_version = '>= 1.9'
|
104
|
-
end
|
105
|
-
|
106
|
-
desc 'Creates a json_pure.gemspec file'
|
107
|
-
task :gemspec_pure => :version do
|
108
|
-
File.open('json_pure.gemspec', 'w') do |gemspec|
|
109
|
-
gemspec.write spec_pure.to_ruby
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
Gem::PackageTask.new(spec_pure) do |pkg|
|
114
|
-
pkg.need_tar = true
|
115
|
-
pkg.package_files = PKG_FILES
|
116
|
-
end
|
117
|
-
|
118
|
-
spec_ext = Gem::Specification.new do |s|
|
119
|
-
s.name = 'json'
|
120
|
-
s.version = PKG_VERSION
|
121
|
-
s.summary = PKG_TITLE
|
122
|
-
s.description = "This is a JSON implementation as a Ruby extension in C."
|
123
|
-
|
124
|
-
s.files = PKG_FILES
|
125
|
-
|
126
|
-
s.extensions = FileList['ext/**/extconf.rb']
|
127
|
-
|
128
|
-
s.require_path = 'lib'
|
129
|
-
s.add_development_dependency 'rake'
|
130
|
-
s.add_development_dependency 'test-unit', '~> 2.0'
|
131
|
-
|
132
|
-
s.extra_rdoc_files << 'README.md'
|
133
|
-
s.rdoc_options <<
|
134
|
-
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.md'
|
135
|
-
s.test_files.concat Dir['./tests/test_*.rb']
|
136
|
-
|
137
|
-
s.author = "Florian Frank"
|
138
|
-
s.email = "flori@ping.de"
|
139
|
-
s.homepage = "http://flori.github.com/#{PKG_NAME}"
|
140
|
-
s.license = 'Ruby'
|
141
|
-
s.required_ruby_version = '>= 1.9'
|
142
|
-
end
|
143
|
-
|
144
|
-
desc 'Creates a json.gemspec file'
|
145
|
-
task :gemspec_ext => :version do
|
146
|
-
File.open('json.gemspec', 'w') do |gemspec|
|
147
|
-
gemspec.write spec_ext.to_ruby
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
Gem::PackageTask.new(spec_ext) do |pkg|
|
152
|
-
pkg.need_tar = true
|
153
|
-
pkg.package_files = PKG_FILES
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
desc 'Create all gemspec files'
|
158
|
-
task :gemspec => [ :gemspec_pure, :gemspec_ext ]
|
159
|
-
end
|
160
|
-
|
161
81
|
desc m = "Writing version information for #{PKG_VERSION}"
|
162
82
|
task :version do
|
163
83
|
puts m
|
@@ -181,7 +101,8 @@ task :check_env do
|
|
181
101
|
end
|
182
102
|
|
183
103
|
desc "Testing library (pure ruby)"
|
184
|
-
task :test_pure => [ :
|
104
|
+
task :test_pure => [ :set_env_pure, :check_env, :do_test_pure ]
|
105
|
+
task(:set_env_pure) { ENV['JSON'] = 'pure' }
|
185
106
|
|
186
107
|
UndocumentedTestTask.new do |t|
|
187
108
|
t.name = 'do_test_pure'
|
@@ -192,10 +113,7 @@ UndocumentedTestTask.new do |t|
|
|
192
113
|
end
|
193
114
|
|
194
115
|
desc "Testing library (pure ruby and extension)"
|
195
|
-
task :test
|
196
|
-
sh "env JSON=pure #{BUNDLE} exec rake test_pure" or exit 1
|
197
|
-
sh "env JSON=ext #{BUNDLE} exec rake test_ext" or exit 1
|
198
|
-
end
|
116
|
+
task :test => [ :test_pure, :test_ext ]
|
199
117
|
|
200
118
|
namespace :gems do
|
201
119
|
desc 'Install all development gems'
|
@@ -262,7 +180,8 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
|
262
180
|
end
|
263
181
|
|
264
182
|
desc "Testing library (jruby)"
|
265
|
-
task :test_ext => [ :
|
183
|
+
task :test_ext => [ :set_env_ext, :create_jar, :check_env, :do_test_ext ]
|
184
|
+
task(:set_env_ext) { ENV['JSON'] = 'ext' }
|
266
185
|
|
267
186
|
UndocumentedTestTask.new do |t|
|
268
187
|
t.name = 'do_test_ext'
|
@@ -368,6 +287,8 @@ else
|
|
368
287
|
end
|
369
288
|
src = File.read("parser.c").gsub(/[ \t]+$/, '')
|
370
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 */"
|
371
292
|
File.open("parser.c", "w") {|f| f.print src}
|
372
293
|
end
|
373
294
|
end
|
@@ -410,4 +331,4 @@ else
|
|
410
331
|
end
|
411
332
|
|
412
333
|
desc "Compile in the the source directory"
|
413
|
-
task :default => [ :clean, :
|
334
|
+
task :default => [ :clean, :test ]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.0
|
@@ -22,7 +22,7 @@ static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
|
22
22
|
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
|
23
23
|
i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
24
24
|
i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth,
|
25
|
-
i_buffer_initial_length, i_dup;
|
25
|
+
i_buffer_initial_length, i_dup, i_escape_slash;
|
26
26
|
|
27
27
|
/*
|
28
28
|
* Copyright 2001-2004 Unicode, Inc.
|
@@ -130,7 +130,7 @@ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16
|
|
130
130
|
|
131
131
|
/* Converts string to a JSON string in FBuffer buffer, where all but the ASCII
|
132
132
|
* and control characters are JSON escaped. */
|
133
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
133
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash)
|
134
134
|
{
|
135
135
|
const UTF8 *source = (UTF8 *) RSTRING_PTR(string);
|
136
136
|
const UTF8 *sourceEnd = source + RSTRING_LEN(string);
|
@@ -180,6 +180,11 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
|
180
180
|
case '"':
|
181
181
|
fbuffer_append(buffer, "\\\"", 2);
|
182
182
|
break;
|
183
|
+
case '/':
|
184
|
+
if(escape_slash) {
|
185
|
+
fbuffer_append(buffer, "\\/", 2);
|
186
|
+
break;
|
187
|
+
}
|
183
188
|
default:
|
184
189
|
fbuffer_append_char(buffer, (char)ch);
|
185
190
|
break;
|
@@ -229,7 +234,7 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
|
229
234
|
* characters required by the JSON standard are JSON escaped. The remaining
|
230
235
|
* characters (should be UTF8) are just passed through and appended to the
|
231
236
|
* result. */
|
232
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
237
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash)
|
233
238
|
{
|
234
239
|
const char *ptr = RSTRING_PTR(string), *p;
|
235
240
|
unsigned long len = RSTRING_LEN(string), start = 0, end = 0;
|
@@ -280,6 +285,12 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
|
280
285
|
escape = "\\\"";
|
281
286
|
escape_len = 2;
|
282
287
|
break;
|
288
|
+
case '/':
|
289
|
+
if(escape_slash) {
|
290
|
+
escape = "\\/";
|
291
|
+
escape_len = 2;
|
292
|
+
break;
|
293
|
+
}
|
283
294
|
default:
|
284
295
|
{
|
285
296
|
unsigned short clen = 1;
|
@@ -328,6 +339,76 @@ static char *fstrndup(const char *ptr, unsigned long len) {
|
|
328
339
|
*
|
329
340
|
*/
|
330
341
|
|
342
|
+
/* Explanation of the following: that's the only way to not pollute
|
343
|
+
* standard library's docs with GeneratorMethods::<ClassName> which
|
344
|
+
* are uninformative and take a large place in a list of classes
|
345
|
+
*/
|
346
|
+
|
347
|
+
/*
|
348
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods
|
349
|
+
* :nodoc:
|
350
|
+
*/
|
351
|
+
|
352
|
+
/*
|
353
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Array
|
354
|
+
* :nodoc:
|
355
|
+
*/
|
356
|
+
|
357
|
+
/*
|
358
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Bignum
|
359
|
+
* :nodoc:
|
360
|
+
*/
|
361
|
+
|
362
|
+
/*
|
363
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::FalseClass
|
364
|
+
* :nodoc:
|
365
|
+
*/
|
366
|
+
|
367
|
+
/*
|
368
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Fixnum
|
369
|
+
* :nodoc:
|
370
|
+
*/
|
371
|
+
|
372
|
+
/*
|
373
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Float
|
374
|
+
* :nodoc:
|
375
|
+
*/
|
376
|
+
|
377
|
+
/*
|
378
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Hash
|
379
|
+
* :nodoc:
|
380
|
+
*/
|
381
|
+
|
382
|
+
/*
|
383
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Integer
|
384
|
+
* :nodoc:
|
385
|
+
*/
|
386
|
+
|
387
|
+
/*
|
388
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::NilClass
|
389
|
+
* :nodoc:
|
390
|
+
*/
|
391
|
+
|
392
|
+
/*
|
393
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::Object
|
394
|
+
* :nodoc:
|
395
|
+
*/
|
396
|
+
|
397
|
+
/*
|
398
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::String
|
399
|
+
* :nodoc:
|
400
|
+
*/
|
401
|
+
|
402
|
+
/*
|
403
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::String::Extend
|
404
|
+
* :nodoc:
|
405
|
+
*/
|
406
|
+
|
407
|
+
/*
|
408
|
+
* Document-module: JSON::Ext::Generator::GeneratorMethods::TrueClass
|
409
|
+
* :nodoc:
|
410
|
+
*/
|
411
|
+
|
331
412
|
/*
|
332
413
|
* call-seq: to_json(state = nil)
|
333
414
|
*
|
@@ -646,6 +727,8 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
646
727
|
state->allow_nan = RTEST(tmp);
|
647
728
|
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
|
648
729
|
state->ascii_only = RTEST(tmp);
|
730
|
+
tmp = rb_hash_aref(opts, ID2SYM(i_escape_slash));
|
731
|
+
state->escape_slash = RTEST(tmp);
|
649
732
|
return self;
|
650
733
|
}
|
651
734
|
|
@@ -680,6 +763,7 @@ static VALUE cState_to_h(VALUE self)
|
|
680
763
|
rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);
|
681
764
|
rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);
|
682
765
|
rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));
|
766
|
+
rb_hash_aset(result, ID2SYM(i_escape_slash), state->escape_slash ? Qtrue : Qfalse);
|
683
767
|
rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));
|
684
768
|
rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));
|
685
769
|
return result;
|
@@ -864,9 +948,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
864
948
|
}
|
865
949
|
#endif
|
866
950
|
if (state->ascii_only) {
|
867
|
-
convert_UTF8_to_JSON_ASCII(buffer, obj);
|
951
|
+
convert_UTF8_to_JSON_ASCII(buffer, obj, state->escape_slash);
|
868
952
|
} else {
|
869
|
-
convert_UTF8_to_JSON(buffer, obj);
|
953
|
+
convert_UTF8_to_JSON(buffer, obj, state->escape_slash);
|
870
954
|
}
|
871
955
|
fbuffer_append_char(buffer, '"');
|
872
956
|
}
|
@@ -1026,7 +1110,7 @@ static VALUE cState_generate(VALUE self, VALUE obj)
|
|
1026
1110
|
* generated, otherwise an exception is thrown, if these values are
|
1027
1111
|
* encountered. This options defaults to false.
|
1028
1112
|
* * *ascii_only*: true if only ASCII characters should be generated. This
|
1029
|
-
*
|
1113
|
+
* option defaults to false.
|
1030
1114
|
* * *buffer_initial_length*: sets the initial length of the generator's
|
1031
1115
|
* internal buffer.
|
1032
1116
|
*/
|
@@ -1307,6 +1391,31 @@ static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
|
|
1307
1391
|
return state->max_nesting = FIX2LONG(depth);
|
1308
1392
|
}
|
1309
1393
|
|
1394
|
+
/*
|
1395
|
+
* call-seq: escape_slash
|
1396
|
+
*
|
1397
|
+
* If this boolean is true, the forward slashes will be escaped in
|
1398
|
+
* the json output.
|
1399
|
+
*/
|
1400
|
+
static VALUE cState_escape_slash(VALUE self)
|
1401
|
+
{
|
1402
|
+
GET_STATE(self);
|
1403
|
+
return state->escape_slash ? Qtrue : Qfalse;
|
1404
|
+
}
|
1405
|
+
|
1406
|
+
/*
|
1407
|
+
* call-seq: escape_slash=(depth)
|
1408
|
+
*
|
1409
|
+
* This sets whether or not the forward slashes will be escaped in
|
1410
|
+
* the json output.
|
1411
|
+
*/
|
1412
|
+
static VALUE cState_escape_slash_set(VALUE self, VALUE enable)
|
1413
|
+
{
|
1414
|
+
GET_STATE(self);
|
1415
|
+
state->escape_slash = RTEST(enable);
|
1416
|
+
return Qnil;
|
1417
|
+
}
|
1418
|
+
|
1310
1419
|
/*
|
1311
1420
|
* call-seq: allow_nan?
|
1312
1421
|
*
|
@@ -1419,6 +1528,9 @@ void Init_generator(void)
|
|
1419
1528
|
rb_define_method(cState, "array_nl=", cState_array_nl_set, 1);
|
1420
1529
|
rb_define_method(cState, "max_nesting", cState_max_nesting, 0);
|
1421
1530
|
rb_define_method(cState, "max_nesting=", cState_max_nesting_set, 1);
|
1531
|
+
rb_define_method(cState, "escape_slash", cState_escape_slash, 0);
|
1532
|
+
rb_define_method(cState, "escape_slash?", cState_escape_slash, 0);
|
1533
|
+
rb_define_method(cState, "escape_slash=", cState_escape_slash_set, 1);
|
1422
1534
|
rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
|
1423
1535
|
rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
|
1424
1536
|
rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
|
@@ -1475,6 +1587,7 @@ void Init_generator(void)
|
|
1475
1587
|
i_object_nl = rb_intern("object_nl");
|
1476
1588
|
i_array_nl = rb_intern("array_nl");
|
1477
1589
|
i_max_nesting = rb_intern("max_nesting");
|
1590
|
+
i_escape_slash = rb_intern("escape_slash");
|
1478
1591
|
i_allow_nan = rb_intern("allow_nan");
|
1479
1592
|
i_ascii_only = rb_intern("ascii_only");
|
1480
1593
|
i_depth = rb_intern("depth");
|
@@ -49,8 +49,8 @@ static const UTF32 halfMask = 0x3FFUL;
|
|
49
49
|
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
50
50
|
static void unicode_escape(char *buf, UTF16 character);
|
51
51
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
52
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
|
53
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
|
52
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash);
|
53
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash);
|
54
54
|
static char *fstrndup(const char *ptr, unsigned long len);
|
55
55
|
|
56
56
|
/* ruby api and some helpers */
|
@@ -72,6 +72,7 @@ typedef struct JSON_Generator_StateStruct {
|
|
72
72
|
long max_nesting;
|
73
73
|
char allow_nan;
|
74
74
|
char ascii_only;
|
75
|
+
char escape_slash;
|
75
76
|
long depth;
|
76
77
|
long buffer_initial_length;
|
77
78
|
} JSON_Generator_State;
|
@@ -150,6 +151,8 @@ static VALUE cState_allow_nan_p(VALUE self);
|
|
150
151
|
static VALUE cState_ascii_only_p(VALUE self);
|
151
152
|
static VALUE cState_depth(VALUE self);
|
152
153
|
static VALUE cState_depth_set(VALUE self, VALUE depth);
|
154
|
+
static VALUE cState_escape_slash(VALUE self);
|
155
|
+
static VALUE cState_escape_slash_set(VALUE self, VALUE depth);
|
153
156
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
154
157
|
#ifndef ZALLOC
|
155
158
|
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
@@ -3,4 +3,29 @@ require 'mkmf'
|
|
3
3
|
|
4
4
|
have_func("rb_enc_raise", "ruby.h")
|
5
5
|
|
6
|
+
# checking if String#-@ (str_uminus) dedupes... '
|
7
|
+
begin
|
8
|
+
a = -(%w(t e s t).join)
|
9
|
+
b = -(%w(t e s t).join)
|
10
|
+
if a.equal?(b)
|
11
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
|
12
|
+
else
|
13
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
14
|
+
end
|
15
|
+
rescue NoMethodError
|
16
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
17
|
+
end
|
18
|
+
|
19
|
+
# checking if String#-@ (str_uminus) directly interns frozen strings... '
|
20
|
+
begin
|
21
|
+
s = rand.to_s.freeze
|
22
|
+
if (-s).equal?(s) && (-s.dup).equal?(s)
|
23
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
|
24
|
+
else
|
25
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
26
|
+
end
|
27
|
+
rescue NoMethodError
|
28
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
29
|
+
end
|
30
|
+
|
6
31
|
create_makefile 'json/ext/parser'
|