json_pure 1.8.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +5 -3
- data/CHANGES +5 -5
- data/Gemfile +3 -1
- data/README.md +131 -84
- data/Rakefile +17 -10
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +1 -52
- data/ext/json/ext/generator/generator.h +0 -5
- data/ext/json/ext/parser/extconf.rb +3 -0
- data/ext/json/ext/parser/parser.c +304 -458
- data/ext/json/ext/parser/parser.h +0 -1
- data/ext/json/ext/parser/parser.rl +35 -152
- data/ext/json/extconf.rb +0 -1
- data/java/src/json/ext/Generator.java +2 -5
- data/java/src/json/ext/GeneratorState.java +2 -54
- data/java/src/json/ext/OptionsReader.java +1 -1
- data/java/src/json/ext/Parser.java +109 -409
- data/java/src/json/ext/Parser.rl +24 -117
- data/java/src/json/ext/RuntimeInfo.java +0 -4
- data/json.gemspec +0 -0
- data/json_pure.gemspec +7 -7
- data/lib/json.rb +1 -0
- data/lib/json/add/bigdecimal.rb +1 -0
- data/lib/json/add/complex.rb +2 -1
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +1 -0
- data/lib/json/add/regexp.rb +1 -1
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -1
- data/lib/json/add/time.rb +1 -1
- data/lib/json/common.rb +24 -52
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure.rb +2 -8
- data/lib/json/pure/generator.rb +51 -123
- data/lib/json/pure/parser.rb +28 -80
- data/lib/json/version.rb +2 -1
- data/references/rfc7159.txt +899 -0
- data/tests/fixtures/obsolete_fail1.json +1 -0
- data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
- data/tests/json_common_interface_test.rb +126 -0
- data/tests/json_encoding_test.rb +105 -0
- data/tests/json_ext_parser_test.rb +15 -0
- data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
- data/tests/{test_json_generate.rb → json_generator_test.rb} +65 -37
- data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
- data/tests/json_parser_test.rb +448 -0
- data/tests/json_string_matching_test.rb +38 -0
- data/tests/test_helper.rb +23 -0
- data/tools/fuzz.rb +1 -9
- metadata +18 -31
- data/TODO +0 -1
- data/tests/fixtures/fail1.json +0 -1
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -519
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
data/java/src/json/ext/Parser.rl
CHANGED
@@ -50,10 +50,9 @@ public class Parser extends RubyObject {
|
|
50
50
|
private int maxNesting;
|
51
51
|
private boolean allowNaN;
|
52
52
|
private boolean symbolizeNames;
|
53
|
-
private boolean quirksMode;
|
54
53
|
private RubyClass objectClass;
|
55
54
|
private RubyClass arrayClass;
|
56
|
-
private RubyHash
|
55
|
+
private RubyHash matchString;
|
57
56
|
|
58
57
|
private static final int DEFAULT_MAX_NESTING = 100;
|
59
58
|
|
@@ -121,10 +120,6 @@ public class Parser extends RubyObject {
|
|
121
120
|
* <dd>If set to <code>true</code>, returns symbols for the names (keys) in
|
122
121
|
* a JSON object. Otherwise strings are returned, which is also the default.
|
123
122
|
*
|
124
|
-
* <dt><code>:quirks_mode?</code>
|
125
|
-
* <dd>If set to <code>true</code>, if the parse is in quirks_mode, false
|
126
|
-
* otherwise.
|
127
|
-
*
|
128
123
|
* <dt><code>:create_additions</code>
|
129
124
|
* <dd>If set to <code>false</code>, the Parser doesn't create additions
|
130
125
|
* even if a matching class and <code>create_id</code> was found. This option
|
@@ -136,9 +131,6 @@ public class Parser extends RubyObject {
|
|
136
131
|
* <dt><code>:array_class</code>
|
137
132
|
* <dd>Defaults to Array.
|
138
133
|
*
|
139
|
-
* <dt><code>:quirks_mode</code>
|
140
|
-
* <dd>Enables quirks_mode for parser, that is for example parsing single
|
141
|
-
* JSON values instead of documents is possible.
|
142
134
|
* </dl>
|
143
135
|
*/
|
144
136
|
@JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
|
@@ -161,15 +153,20 @@ public class Parser extends RubyObject {
|
|
161
153
|
this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
|
162
154
|
this.allowNaN = opts.getBool("allow_nan", false);
|
163
155
|
this.symbolizeNames = opts.getBool("symbolize_names", false);
|
164
|
-
this.quirksMode = opts.getBool("quirks_mode", false);
|
165
156
|
this.createId = opts.getString("create_id", getCreateId(context));
|
166
157
|
this.createAdditions = opts.getBool("create_additions", false);
|
167
158
|
this.objectClass = opts.getClass("object_class", runtime.getHash());
|
168
159
|
this.arrayClass = opts.getClass("array_class", runtime.getArray());
|
169
|
-
this.
|
160
|
+
this.matchString = opts.getHash("match_string");
|
170
161
|
|
162
|
+
if(symbolizeNames && createAdditions) {
|
163
|
+
throw runtime.newArgumentError(
|
164
|
+
"options :symbolize_names and :create_additions cannot be " +
|
165
|
+
" used in conjunction"
|
166
|
+
);
|
167
|
+
}
|
171
168
|
this.vSource = args[0].convertToString();
|
172
|
-
|
169
|
+
this.vSource = convertEncoding(context, vSource);
|
173
170
|
|
174
171
|
return this;
|
175
172
|
}
|
@@ -180,33 +177,13 @@ public class Parser extends RubyObject {
|
|
180
177
|
* Returns the source string if no conversion is needed.
|
181
178
|
*/
|
182
179
|
private RubyString convertEncoding(ThreadContext context, RubyString source) {
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
if (info.encodingsSupported()) {
|
191
|
-
RubyEncoding encoding = (RubyEncoding)source.encoding(context);
|
192
|
-
if (encoding != info.ascii8bit.get()) {
|
193
|
-
return (RubyString)source.encode(context, info.utf8.get());
|
194
|
-
}
|
195
|
-
|
196
|
-
String sniffedEncoding = sniffByteList(bl);
|
197
|
-
if (sniffedEncoding == null) return source; // assume UTF-8
|
198
|
-
return reinterpretEncoding(context, source, sniffedEncoding);
|
199
|
-
}
|
200
|
-
|
201
|
-
String sniffedEncoding = sniffByteList(bl);
|
202
|
-
if (sniffedEncoding == null) return source; // assume UTF-8
|
203
|
-
Ruby runtime = context.getRuntime();
|
204
|
-
return (RubyString)info.jsonModule.get().
|
205
|
-
callMethod(context, "iconv",
|
206
|
-
new IRubyObject[] {
|
207
|
-
runtime.newString("utf-8"),
|
208
|
-
runtime.newString(sniffedEncoding),
|
209
|
-
source});
|
180
|
+
RubyEncoding encoding = (RubyEncoding)source.encoding(context);
|
181
|
+
if (encoding == info.ascii8bit.get()) {
|
182
|
+
source.force_encoding(context, info.utf8.get());
|
183
|
+
} else {
|
184
|
+
source = (RubyString) source.encode(context, info.utf8.get());
|
185
|
+
}
|
186
|
+
return source;
|
210
187
|
}
|
211
188
|
|
212
189
|
/**
|
@@ -259,17 +236,6 @@ public class Parser extends RubyObject {
|
|
259
236
|
return checkAndGetSource().dup();
|
260
237
|
}
|
261
238
|
|
262
|
-
/**
|
263
|
-
* <code>Parser#quirks_mode?()</code>
|
264
|
-
*
|
265
|
-
* <p>If set to <code>true</code>, if the parse is in quirks_mode, false
|
266
|
-
* otherwise.
|
267
|
-
*/
|
268
|
-
@JRubyMethod(name = "quirks_mode?")
|
269
|
-
public IRubyObject quirks_mode_p(ThreadContext context) {
|
270
|
-
return context.getRuntime().newBoolean(quirksMode);
|
271
|
-
}
|
272
|
-
|
273
239
|
public RubyString checkAndGetSource() {
|
274
240
|
if (vSource != null) {
|
275
241
|
return vSource;
|
@@ -393,7 +359,7 @@ public class Parser extends RubyObject {
|
|
393
359
|
}
|
394
360
|
}
|
395
361
|
action parse_number {
|
396
|
-
if (pe > fpc +
|
362
|
+
if (pe > fpc + 8 &&
|
397
363
|
absSubSequence(fpc, fpc + 9).equals(JSON_MINUS_INFINITY)) {
|
398
364
|
|
399
365
|
if (parser.allowNaN) {
|
@@ -623,11 +589,11 @@ public class Parser extends RubyObject {
|
|
623
589
|
%% write exec;
|
624
590
|
|
625
591
|
if (parser.createAdditions) {
|
626
|
-
RubyHash
|
627
|
-
if (
|
592
|
+
RubyHash matchString = parser.matchString;
|
593
|
+
if (matchString != null) {
|
628
594
|
final IRubyObject[] memoArray = { result, null };
|
629
595
|
try {
|
630
|
-
|
596
|
+
matchString.visitAll(new RubyHash.Visitor() {
|
631
597
|
@Override
|
632
598
|
public void visit(IRubyObject pattern, IRubyObject klass) {
|
633
599
|
if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
|
@@ -648,7 +614,7 @@ public class Parser extends RubyObject {
|
|
648
614
|
}
|
649
615
|
|
650
616
|
if (cs >= JSON_string_first_final && result != null) {
|
651
|
-
if (
|
617
|
+
if (result instanceof RubyString) {
|
652
618
|
((RubyString)result).force_encoding(context, info.utf8.get());
|
653
619
|
}
|
654
620
|
res.update(result, p + 1);
|
@@ -835,60 +801,6 @@ public class Parser extends RubyObject {
|
|
835
801
|
|
836
802
|
write data;
|
837
803
|
|
838
|
-
action parse_object {
|
839
|
-
currentNesting = 1;
|
840
|
-
parseObject(res, fpc, pe);
|
841
|
-
if (res.result == null) {
|
842
|
-
fhold;
|
843
|
-
fbreak;
|
844
|
-
} else {
|
845
|
-
result = res.result;
|
846
|
-
fexec res.p;
|
847
|
-
}
|
848
|
-
}
|
849
|
-
|
850
|
-
action parse_array {
|
851
|
-
currentNesting = 1;
|
852
|
-
parseArray(res, fpc, pe);
|
853
|
-
if (res.result == null) {
|
854
|
-
fhold;
|
855
|
-
fbreak;
|
856
|
-
} else {
|
857
|
-
result = res.result;
|
858
|
-
fexec res.p;
|
859
|
-
}
|
860
|
-
}
|
861
|
-
|
862
|
-
main := ignore*
|
863
|
-
( begin_object >parse_object
|
864
|
-
| begin_array >parse_array )
|
865
|
-
ignore*;
|
866
|
-
}%%
|
867
|
-
|
868
|
-
public IRubyObject parseStrict() {
|
869
|
-
int cs = EVIL;
|
870
|
-
int p, pe;
|
871
|
-
IRubyObject result = null;
|
872
|
-
ParserResult res = new ParserResult();
|
873
|
-
|
874
|
-
%% write init;
|
875
|
-
p = byteList.begin();
|
876
|
-
pe = p + byteList.length();
|
877
|
-
%% write exec;
|
878
|
-
|
879
|
-
if (cs >= JSON_first_final && p == pe) {
|
880
|
-
return result;
|
881
|
-
} else {
|
882
|
-
throw unexpectedToken(p, pe);
|
883
|
-
}
|
884
|
-
}
|
885
|
-
|
886
|
-
%%{
|
887
|
-
machine JSON_quirks_mode;
|
888
|
-
include JSON_common;
|
889
|
-
|
890
|
-
write data;
|
891
|
-
|
892
804
|
action parse_value {
|
893
805
|
parseValue(res, fpc, pe);
|
894
806
|
if (res.result == null) {
|
@@ -905,7 +817,7 @@ public class Parser extends RubyObject {
|
|
905
817
|
ignore*;
|
906
818
|
}%%
|
907
819
|
|
908
|
-
public IRubyObject
|
820
|
+
public IRubyObject parseImplemetation() {
|
909
821
|
int cs = EVIL;
|
910
822
|
int p, pe;
|
911
823
|
IRubyObject result = null;
|
@@ -916,7 +828,7 @@ public class Parser extends RubyObject {
|
|
916
828
|
pe = p + byteList.length();
|
917
829
|
%% write exec;
|
918
830
|
|
919
|
-
if (cs >=
|
831
|
+
if (cs >= JSON_first_final && p == pe) {
|
920
832
|
return result;
|
921
833
|
} else {
|
922
834
|
throw unexpectedToken(p, pe);
|
@@ -924,12 +836,7 @@ public class Parser extends RubyObject {
|
|
924
836
|
}
|
925
837
|
|
926
838
|
public IRubyObject parse() {
|
927
|
-
|
928
|
-
return parseQuirksMode();
|
929
|
-
} else {
|
930
|
-
return parseStrict();
|
931
|
-
}
|
932
|
-
|
839
|
+
return parseImplemetation();
|
933
840
|
}
|
934
841
|
|
935
842
|
/**
|
@@ -90,10 +90,6 @@ final class RuntimeInfo {
|
|
90
90
|
}
|
91
91
|
}
|
92
92
|
|
93
|
-
public boolean encodingsSupported() {
|
94
|
-
return utf8 != null && utf8.get() != null;
|
95
|
-
}
|
96
|
-
|
97
93
|
public RubyEncoding getEncoding(ThreadContext context, String name) {
|
98
94
|
synchronized (encodings) {
|
99
95
|
WeakReference<RubyEncoding> encoding = encodings.get(name);
|
data/json.gemspec
CHANGED
Binary file
|
data/json_pure.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: json_pure
|
2
|
+
# stub: json_pure 2.0.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "json_pure".freeze
|
6
|
-
s.version = "
|
6
|
+
s.version = "2.0.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2016-07-01"
|
12
12
|
s.description = "This is a JSON implementation in pure Ruby.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze]
|
15
|
-
s.files = ["./tests/
|
15
|
+
s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES".freeze, "Gemfile".freeze, "README-json-jruby.markdown".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "data/example.json".freeze, "data/index.html".freeze, "data/prototype.js".freeze, "diagrams/.keep".freeze, "ext/json/ext/fbuffer/fbuffer.h".freeze, "ext/json/ext/generator/depend".freeze, "ext/json/ext/generator/extconf.rb".freeze, "ext/json/ext/generator/generator.c".freeze, "ext/json/ext/generator/generator.h".freeze, "ext/json/ext/parser/depend".freeze, "ext/json/ext/parser/extconf.rb".freeze, "ext/json/ext/parser/parser.c".freeze, "ext/json/ext/parser/parser.h".freeze, "ext/json/ext/parser/parser.rl".freeze, "ext/json/extconf.rb".freeze, "install.rb".freeze, "java/src/json/ext/ByteListTranscoder.java".freeze, "java/src/json/ext/Generator.java".freeze, "java/src/json/ext/GeneratorMethods.java".freeze, "java/src/json/ext/GeneratorService.java".freeze, "java/src/json/ext/GeneratorState.java".freeze, "java/src/json/ext/OptionsReader.java".freeze, "java/src/json/ext/Parser.java".freeze, "java/src/json/ext/Parser.rl".freeze, "java/src/json/ext/ParserService.java".freeze, "java/src/json/ext/RuntimeInfo.java".freeze, "java/src/json/ext/StringDecoder.java".freeze, "java/src/json/ext/StringEncoder.java".freeze, "java/src/json/ext/Utils.java".freeze, "json-java.gemspec".freeze, "json.gemspec".freeze, "json_pure.gemspec".freeze, "lib/json.rb".freeze, "lib/json/add/bigdecimal.rb".freeze, "lib/json/add/complex.rb".freeze, "lib/json/add/core.rb".freeze, "lib/json/add/date.rb".freeze, "lib/json/add/date_time.rb".freeze, "lib/json/add/exception.rb".freeze, "lib/json/add/ostruct.rb".freeze, "lib/json/add/range.rb".freeze, "lib/json/add/rational.rb".freeze, "lib/json/add/regexp.rb".freeze, "lib/json/add/struct.rb".freeze, "lib/json/add/symbol.rb".freeze, "lib/json/add/time.rb".freeze, "lib/json/common.rb".freeze, "lib/json/ext.rb".freeze, "lib/json/ext/.keep".freeze, "lib/json/generic_object.rb".freeze, "lib/json/pure.rb".freeze, "lib/json/pure/generator.rb".freeze, "lib/json/pure/parser.rb".freeze, "lib/json/version.rb".freeze, "references/rfc7159.txt".freeze, "tests/fixtures/fail10.json".freeze, "tests/fixtures/fail11.json".freeze, "tests/fixtures/fail12.json".freeze, "tests/fixtures/fail13.json".freeze, "tests/fixtures/fail14.json".freeze, "tests/fixtures/fail18.json".freeze, "tests/fixtures/fail19.json".freeze, "tests/fixtures/fail2.json".freeze, "tests/fixtures/fail20.json".freeze, "tests/fixtures/fail21.json".freeze, "tests/fixtures/fail22.json".freeze, "tests/fixtures/fail23.json".freeze, "tests/fixtures/fail24.json".freeze, "tests/fixtures/fail25.json".freeze, "tests/fixtures/fail27.json".freeze, "tests/fixtures/fail28.json".freeze, "tests/fixtures/fail3.json".freeze, "tests/fixtures/fail4.json".freeze, "tests/fixtures/fail5.json".freeze, "tests/fixtures/fail6.json".freeze, "tests/fixtures/fail7.json".freeze, "tests/fixtures/fail8.json".freeze, "tests/fixtures/fail9.json".freeze, "tests/fixtures/obsolete_fail1.json".freeze, "tests/fixtures/pass1.json".freeze, "tests/fixtures/pass15.json".freeze, "tests/fixtures/pass16.json".freeze, "tests/fixtures/pass17.json".freeze, "tests/fixtures/pass2.json".freeze, "tests/fixtures/pass26.json".freeze, "tests/fixtures/pass3.json".freeze, "tests/json_addition_test.rb".freeze, "tests/json_common_interface_test.rb".freeze, "tests/json_encoding_test.rb".freeze, "tests/json_ext_parser_test.rb".freeze, "tests/json_fixtures_test.rb".freeze, "tests/json_generator_test.rb".freeze, "tests/json_generic_object_test.rb".freeze, "tests/json_parser_test.rb".freeze, "tests/json_string_matching_test.rb".freeze, "tests/test_helper.rb".freeze, "tools/diff.sh".freeze, "tools/fuzz.rb".freeze, "tools/server.rb".freeze]
|
16
16
|
s.homepage = "http://flori.github.com/json".freeze
|
17
17
|
s.licenses = ["Ruby".freeze]
|
18
|
-
s.rdoc_options = ["--title".freeze, "JSON implemention for
|
19
|
-
s.rubygems_version = "2.6.
|
18
|
+
s.rdoc_options = ["--title".freeze, "JSON implemention for ruby".freeze, "--main".freeze, "README.md".freeze]
|
19
|
+
s.rubygems_version = "2.6.4".freeze
|
20
20
|
s.summary = "JSON Implementation for Ruby".freeze
|
21
|
-
s.test_files = ["./tests/
|
21
|
+
s.test_files = ["./tests/test_helper.rb".freeze]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 4
|
data/lib/json.rb
CHANGED
data/lib/json/add/bigdecimal.rb
CHANGED
data/lib/json/add/complex.rb
CHANGED
data/lib/json/add/core.rb
CHANGED
data/lib/json/add/date.rb
CHANGED
data/lib/json/add/date_time.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
#frozen_string_literal: false
|
1
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
3
|
require 'json'
|
3
4
|
end
|
4
5
|
require 'date'
|
5
6
|
|
6
|
-
# DateTime serialization/deserialization
|
7
7
|
class DateTime
|
8
8
|
|
9
9
|
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
data/lib/json/add/exception.rb
CHANGED
data/lib/json/add/ostruct.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
#frozen_string_literal: false
|
1
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
3
|
require 'json'
|
3
4
|
end
|
4
5
|
require 'ostruct'
|
5
6
|
|
6
|
-
# OpenStruct serialization/deserialization
|
7
7
|
class OpenStruct
|
8
8
|
|
9
9
|
# Deserializes JSON string by constructing new Struct object with values
|
data/lib/json/add/range.rb
CHANGED
data/lib/json/add/rational.rb
CHANGED
data/lib/json/add/regexp.rb
CHANGED
data/lib/json/add/struct.rb
CHANGED
data/lib/json/add/symbol.rb
CHANGED
data/lib/json/add/time.rb
CHANGED
data/lib/json/common.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
#frozen_string_literal: false
|
1
2
|
require 'json/version'
|
2
3
|
require 'json/generic_object'
|
3
4
|
|
4
5
|
module JSON
|
5
6
|
class << self
|
6
|
-
# If _object_ is string-like, parse the string and return the parsed
|
7
|
-
# as a Ruby data structure. Otherwise generate a JSON text from the
|
8
|
-
# data structure object and return it.
|
7
|
+
# If _object_ is string-like, parse the string and return the parsed
|
8
|
+
# result as a Ruby data structure. Otherwise generate a JSON text from the
|
9
|
+
# Ruby data structure object and return it.
|
9
10
|
#
|
10
|
-
# The _opts_ argument is passed through to generate/parse respectively.
|
11
|
-
# generate and parse for their documentation.
|
11
|
+
# The _opts_ argument is passed through to generate/parse respectively.
|
12
|
+
# See generate and parse for their documentation.
|
12
13
|
def [](object, opts = {})
|
13
14
|
if object.respond_to? :to_str
|
14
15
|
JSON.parse(object.to_str, opts)
|
@@ -24,7 +25,7 @@ module JSON
|
|
24
25
|
# Set the JSON parser class _parser_ to be used by JSON.
|
25
26
|
def parser=(parser) # :nodoc:
|
26
27
|
@parser = parser
|
27
|
-
remove_const :Parser if
|
28
|
+
remove_const :Parser if const_defined?(:Parser, true)
|
28
29
|
const_set :Parser, parser
|
29
30
|
end
|
30
31
|
|
@@ -35,8 +36,8 @@ module JSON
|
|
35
36
|
def deep_const_get(path) # :nodoc:
|
36
37
|
path.to_s.split(/::/).inject(Object) do |p, c|
|
37
38
|
case
|
38
|
-
when c.empty?
|
39
|
-
when
|
39
|
+
when c.empty? then p
|
40
|
+
when p.const_defined?(c, true) then p.const_get(c)
|
40
41
|
else
|
41
42
|
begin
|
42
43
|
p.const_missing(c)
|
@@ -138,10 +139,10 @@ module JSON
|
|
138
139
|
# _opts_ can have the following
|
139
140
|
# keys:
|
140
141
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
141
|
-
# structures. Disable depth checking with :max_nesting => false. It
|
142
|
-
# to 100.
|
142
|
+
# structures. Disable depth checking with :max_nesting => false. It
|
143
|
+
# defaults to 100.
|
143
144
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
144
|
-
# defiance of RFC
|
145
|
+
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
145
146
|
# to false.
|
146
147
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
147
148
|
# (keys) in a JSON object. Otherwise strings are returned. Strings are
|
@@ -161,11 +162,11 @@ module JSON
|
|
161
162
|
#
|
162
163
|
# _opts_ can have the following keys:
|
163
164
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
164
|
-
# structures. Enable depth checking with :max_nesting => anInteger. The
|
165
|
-
# methods defaults to not doing max depth checking: This can be
|
166
|
-
# if someone wants to fill up your stack.
|
165
|
+
# structures. Enable depth checking with :max_nesting => anInteger. The
|
166
|
+
# parse! methods defaults to not doing max depth checking: This can be
|
167
|
+
# dangerous if someone wants to fill up your stack.
|
167
168
|
# * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
|
168
|
-
# defiance of RFC
|
169
|
+
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
169
170
|
# to true.
|
170
171
|
# * *create_additions*: If set to false, the Parser doesn't create
|
171
172
|
# additions even if a matching class and create_id was found. This option
|
@@ -174,7 +175,7 @@ module JSON
|
|
174
175
|
opts = {
|
175
176
|
:max_nesting => false,
|
176
177
|
:allow_nan => true
|
177
|
-
}.
|
178
|
+
}.merge(opts)
|
178
179
|
Parser.new(source, opts).parse
|
179
180
|
end
|
180
181
|
|
@@ -295,13 +296,13 @@ module JSON
|
|
295
296
|
# The global default options for the JSON.load method:
|
296
297
|
# :max_nesting: false
|
297
298
|
# :allow_nan: true
|
298
|
-
# :
|
299
|
+
# :allow_blank: true
|
299
300
|
attr_accessor :load_default_options
|
300
301
|
end
|
301
302
|
self.load_default_options = {
|
302
303
|
:max_nesting => false,
|
303
304
|
:allow_nan => true,
|
304
|
-
:
|
305
|
+
:allow_blank => true,
|
305
306
|
:create_additions => true,
|
306
307
|
}
|
307
308
|
|
@@ -328,7 +329,7 @@ module JSON
|
|
328
329
|
elsif source.respond_to?(:read)
|
329
330
|
source = source.read
|
330
331
|
end
|
331
|
-
if opts[:
|
332
|
+
if opts[:allow_blank] && (source.nil? || source.empty?)
|
332
333
|
source = 'null'
|
333
334
|
end
|
334
335
|
result = parse(source, opts)
|
@@ -357,13 +358,12 @@ module JSON
|
|
357
358
|
# The global default options for the JSON.dump method:
|
358
359
|
# :max_nesting: false
|
359
360
|
# :allow_nan: true
|
360
|
-
# :
|
361
|
+
# :allow_blank: true
|
361
362
|
attr_accessor :dump_default_options
|
362
363
|
end
|
363
364
|
self.dump_default_options = {
|
364
365
|
:max_nesting => false,
|
365
366
|
:allow_nan => true,
|
366
|
-
:quirks_mode => true,
|
367
367
|
}
|
368
368
|
|
369
369
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
@@ -402,37 +402,9 @@ module JSON
|
|
402
402
|
raise ArgumentError, "exceed depth limit"
|
403
403
|
end
|
404
404
|
|
405
|
-
#
|
406
|
-
def self.
|
407
|
-
|
408
|
-
break unless string[2 * i + 1]
|
409
|
-
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
410
|
-
end
|
411
|
-
string
|
412
|
-
end
|
413
|
-
|
414
|
-
# Shortcut for iconv.
|
415
|
-
if ::String.method_defined?(:encode)
|
416
|
-
# Encodes string using Ruby's _String.encode_
|
417
|
-
def self.iconv(to, from, string)
|
418
|
-
string.encode(to, from)
|
419
|
-
end
|
420
|
-
else
|
421
|
-
require 'iconv'
|
422
|
-
# Encodes string using _iconv_ library
|
423
|
-
def self.iconv(to, from, string)
|
424
|
-
Iconv.conv(to, from, string)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
if ::Object.method(:const_defined?).arity == 1
|
429
|
-
def self.const_defined_in?(modul, constant)
|
430
|
-
modul.const_defined?(constant)
|
431
|
-
end
|
432
|
-
else
|
433
|
-
def self.const_defined_in?(modul, constant)
|
434
|
-
modul.const_defined?(constant, false)
|
435
|
-
end
|
405
|
+
# Encodes string using Ruby's _String.encode_
|
406
|
+
def self.iconv(to, from, string)
|
407
|
+
string.encode(to, from)
|
436
408
|
end
|
437
409
|
end
|
438
410
|
|