es-scout 5.3.0.es1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +4 -0
- data/CHANGELOG +225 -0
- data/COPYING +340 -0
- data/INSTALL +18 -0
- data/LICENSE +6 -0
- data/README +66 -0
- data/Rakefile +74 -0
- data/TODO +6 -0
- data/bin/es-scout +10 -0
- data/data/cacert.pem +3154 -0
- data/data/code_key.pub +13 -0
- data/data/gpl-2.0.txt +339 -0
- data/data/lgpl-2.1.txt +504 -0
- data/lib/es-scout/command/install.rb +68 -0
- data/lib/es-scout/command/run.rb +56 -0
- data/lib/es-scout/command/test.rb +62 -0
- data/lib/es-scout/command/troubleshoot.rb +142 -0
- data/lib/es-scout/command.rb +258 -0
- data/lib/es-scout/plugin.rb +237 -0
- data/lib/es-scout/plugin_options.rb +80 -0
- data/lib/es-scout/scout_logger.rb +19 -0
- data/lib/es-scout/server.rb +578 -0
- data/lib/es-scout.rb +11 -0
- data/vendor/json_pure/CHANGES +162 -0
- data/vendor/json_pure/COPYING +58 -0
- data/vendor/json_pure/GPL +340 -0
- data/vendor/json_pure/README +358 -0
- data/vendor/json_pure/Rakefile +292 -0
- data/vendor/json_pure/TODO +1 -0
- data/vendor/json_pure/VERSION +1 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
- data/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
- data/vendor/json_pure/benchmarks/generator_benchmark.rb +224 -0
- data/vendor/json_pure/benchmarks/ohai.json +1216 -0
- data/vendor/json_pure/benchmarks/ohai.ruby +1 -0
- data/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
- data/vendor/json_pure/benchmarks/parser_benchmark.rb +259 -0
- data/vendor/json_pure/bin/edit_json.rb +9 -0
- data/vendor/json_pure/bin/prettify_json.rb +75 -0
- data/vendor/json_pure/data/example.json +1 -0
- data/vendor/json_pure/data/index.html +38 -0
- data/vendor/json_pure/data/prototype.js +4184 -0
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +16 -0
- data/vendor/json_pure/ext/json/ext/generator/generator.c +1341 -0
- data/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +15 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.c +1935 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +792 -0
- data/vendor/json_pure/install.rb +26 -0
- data/vendor/json_pure/lib/json/Array.xpm +21 -0
- data/vendor/json_pure/lib/json/FalseClass.xpm +21 -0
- data/vendor/json_pure/lib/json/Hash.xpm +21 -0
- data/vendor/json_pure/lib/json/Key.xpm +73 -0
- data/vendor/json_pure/lib/json/NilClass.xpm +21 -0
- data/vendor/json_pure/lib/json/Numeric.xpm +28 -0
- data/vendor/json_pure/lib/json/String.xpm +96 -0
- data/vendor/json_pure/lib/json/TrueClass.xpm +21 -0
- data/vendor/json_pure/lib/json/add/core.rb +148 -0
- data/vendor/json_pure/lib/json/add/rails.rb +58 -0
- data/vendor/json_pure/lib/json/common.rb +397 -0
- data/vendor/json_pure/lib/json/editor.rb +1371 -0
- data/vendor/json_pure/lib/json/ext.rb +15 -0
- data/vendor/json_pure/lib/json/json.xpm +1499 -0
- data/vendor/json_pure/lib/json/pure/generator.rb +452 -0
- data/vendor/json_pure/lib/json/pure/parser.rb +307 -0
- data/vendor/json_pure/lib/json/pure.rb +77 -0
- data/vendor/json_pure/lib/json/version.rb +8 -0
- data/vendor/json_pure/lib/json.rb +10 -0
- data/vendor/json_pure/tests/fixtures/fail1.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail10.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail11.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail12.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail13.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail14.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail18.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail19.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail2.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail20.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail21.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail22.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail23.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail24.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail25.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail27.json +2 -0
- data/vendor/json_pure/tests/fixtures/fail28.json +2 -0
- data/vendor/json_pure/tests/fixtures/fail3.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail4.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail5.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail6.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail7.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail8.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail9.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass1.json +56 -0
- data/vendor/json_pure/tests/fixtures/pass15.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass16.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass17.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass2.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass26.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass3.json +6 -0
- data/vendor/json_pure/tests/test_json.rb +340 -0
- data/vendor/json_pure/tests/test_json_addition.rb +162 -0
- data/vendor/json_pure/tests/test_json_encoding.rb +68 -0
- data/vendor/json_pure/tests/test_json_fixtures.rb +34 -0
- data/vendor/json_pure/tests/test_json_generate.rb +122 -0
- data/vendor/json_pure/tests/test_json_rails.rb +144 -0
- data/vendor/json_pure/tests/test_json_unicode.rb +76 -0
- data/vendor/json_pure/tools/fuzz.rb +139 -0
- data/vendor/json_pure/tools/server.rb +61 -0
- metadata +233 -0
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
module Pure
|
5
|
+
# This class implements the JSON parser that is used to parse a JSON string
|
6
|
+
# into a Ruby data structure.
|
7
|
+
class Parser < StringScanner
|
8
|
+
STRING = /" ((?:[^\x0-\x1f"\\] |
|
9
|
+
# escaped special characters:
|
10
|
+
\\["\\\/bfnrt] |
|
11
|
+
\\u[0-9a-fA-F]{4} |
|
12
|
+
# match all but escaped special characters:
|
13
|
+
\\[\x20-\x21\x23-\x2e\x30-\x5b\x5d-\x61\x63-\x65\x67-\x6d\x6f-\x71\x73\x75-\xff])*)
|
14
|
+
"/nx
|
15
|
+
INTEGER = /(-?0|-?[1-9]\d*)/
|
16
|
+
FLOAT = /(-?
|
17
|
+
(?:0|[1-9]\d*)
|
18
|
+
(?:
|
19
|
+
\.\d+(?i:e[+-]?\d+) |
|
20
|
+
\.\d+ |
|
21
|
+
(?i:e[+-]?\d+)
|
22
|
+
)
|
23
|
+
)/x
|
24
|
+
NAN = /NaN/
|
25
|
+
INFINITY = /Infinity/
|
26
|
+
MINUS_INFINITY = /-Infinity/
|
27
|
+
OBJECT_OPEN = /\{/
|
28
|
+
OBJECT_CLOSE = /\}/
|
29
|
+
ARRAY_OPEN = /\[/
|
30
|
+
ARRAY_CLOSE = /\]/
|
31
|
+
PAIR_DELIMITER = /:/
|
32
|
+
COLLECTION_DELIMITER = /,/
|
33
|
+
TRUE = /true/
|
34
|
+
FALSE = /false/
|
35
|
+
NULL = /null/
|
36
|
+
IGNORE = %r(
|
37
|
+
(?:
|
38
|
+
//[^\n\r]*[\n\r]| # line comments
|
39
|
+
/\* # c-style comments
|
40
|
+
(?:
|
41
|
+
[^*/]| # normal chars
|
42
|
+
/[^*]| # slashes that do not start a nested comment
|
43
|
+
\*[^/]| # asterisks that do not end this comment
|
44
|
+
/(?=\*/) # single slash before this comment's end
|
45
|
+
)*
|
46
|
+
\*/ # the End of this comment
|
47
|
+
|[ \t\r\n]+ # whitespaces: space, horicontal tab, lf, cr
|
48
|
+
)+
|
49
|
+
)mx
|
50
|
+
|
51
|
+
UNPARSED = Object.new
|
52
|
+
|
53
|
+
# Creates a new JSON::Pure::Parser instance for the string _source_.
|
54
|
+
#
|
55
|
+
# It will be configured by the _opts_ hash. _opts_ can have the following
|
56
|
+
# keys:
|
57
|
+
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
58
|
+
# structures. Disable depth checking with :max_nesting => false|nil|0,
|
59
|
+
# it defaults to 19.
|
60
|
+
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
61
|
+
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
62
|
+
# to false.
|
63
|
+
# * *symbolize_names*: If set to true, returns symbols for the names
|
64
|
+
# (keys) in a JSON object. Otherwise strings are returned, which is also
|
65
|
+
# the default.
|
66
|
+
# * *create_additions*: If set to false, the Parser doesn't create
|
67
|
+
# additions even if a matchin class and create_id was found. This option
|
68
|
+
# defaults to true.
|
69
|
+
# * *object_class*: Defaults to Hash
|
70
|
+
# * *array_class*: Defaults to Array
|
71
|
+
def initialize(source, opts = {})
|
72
|
+
if defined?(::Encoding)
|
73
|
+
if source.encoding == Encoding::ASCII_8BIT
|
74
|
+
b = source[0, 4].bytes.to_a
|
75
|
+
source = case
|
76
|
+
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
|
77
|
+
source.dup.force_encoding(Encoding::UTF_32BE).encode!(Encoding::UTF_8)
|
78
|
+
when b.size >= 4 && b[0] == 0 && b[2] == 0
|
79
|
+
source.dup.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8)
|
80
|
+
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
|
81
|
+
source.dup.force_encoding(Encoding::UTF_32LE).encode!(Encoding::UTF_8)
|
82
|
+
when b.size >= 4 && b[1] == 0 && b[3] == 0
|
83
|
+
source.dup.force_encoding(Encoding::UTF_16LE).encode!(Encoding::UTF_8)
|
84
|
+
else
|
85
|
+
source.dup
|
86
|
+
end
|
87
|
+
else
|
88
|
+
source = source.encode(Encoding::UTF_8)
|
89
|
+
end
|
90
|
+
source.force_encoding(Encoding::ASCII_8BIT)
|
91
|
+
else
|
92
|
+
b = source
|
93
|
+
source = case
|
94
|
+
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
|
95
|
+
JSON.iconv('utf-8', 'utf-32be', b)
|
96
|
+
when b.size >= 4 && b[0] == 0 && b[2] == 0
|
97
|
+
JSON.iconv('utf-8', 'utf-16be', b)
|
98
|
+
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
|
99
|
+
JSON.iconv('utf-8', 'utf-32le', b)
|
100
|
+
when b.size >= 4 && b[1] == 0 && b[3] == 0
|
101
|
+
JSON.iconv('utf-8', 'utf-16le', b)
|
102
|
+
else
|
103
|
+
b
|
104
|
+
end
|
105
|
+
end
|
106
|
+
super source
|
107
|
+
if !opts.key?(:max_nesting) # defaults to 19
|
108
|
+
@max_nesting = 19
|
109
|
+
elsif opts[:max_nesting]
|
110
|
+
@max_nesting = opts[:max_nesting]
|
111
|
+
else
|
112
|
+
@max_nesting = 0
|
113
|
+
end
|
114
|
+
@allow_nan = !!opts[:allow_nan]
|
115
|
+
@symbolize_names = !!opts[:symbolize_names]
|
116
|
+
ca = true
|
117
|
+
ca = opts[:create_additions] if opts.key?(:create_additions)
|
118
|
+
@create_id = ca ? JSON.create_id : nil
|
119
|
+
@object_class = opts[:object_class] || Hash
|
120
|
+
@array_class = opts[:array_class] || Array
|
121
|
+
end
|
122
|
+
|
123
|
+
alias source string
|
124
|
+
|
125
|
+
# Parses the current JSON string _source_ and returns the complete data
|
126
|
+
# structure as a result.
|
127
|
+
def parse
|
128
|
+
reset
|
129
|
+
obj = nil
|
130
|
+
until eos?
|
131
|
+
case
|
132
|
+
when scan(OBJECT_OPEN)
|
133
|
+
obj and raise ParserError, "source '#{peek(20)}' not in JSON!"
|
134
|
+
@current_nesting = 1
|
135
|
+
obj = parse_object
|
136
|
+
when scan(ARRAY_OPEN)
|
137
|
+
obj and raise ParserError, "source '#{peek(20)}' not in JSON!"
|
138
|
+
@current_nesting = 1
|
139
|
+
obj = parse_array
|
140
|
+
when skip(IGNORE)
|
141
|
+
;
|
142
|
+
else
|
143
|
+
raise ParserError, "source '#{peek(20)}' not in JSON!"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
obj or raise ParserError, "source did not contain any JSON!"
|
147
|
+
obj
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
# Unescape characters in strings.
|
153
|
+
UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
|
154
|
+
UNESCAPE_MAP.update({
|
155
|
+
?" => '"',
|
156
|
+
?\\ => '\\',
|
157
|
+
?/ => '/',
|
158
|
+
?b => "\b",
|
159
|
+
?f => "\f",
|
160
|
+
?n => "\n",
|
161
|
+
?r => "\r",
|
162
|
+
?t => "\t",
|
163
|
+
?u => nil,
|
164
|
+
})
|
165
|
+
|
166
|
+
def parse_string
|
167
|
+
if scan(STRING)
|
168
|
+
return '' if self[1].empty?
|
169
|
+
string = self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
|
170
|
+
if u = UNESCAPE_MAP[$&[1]]
|
171
|
+
u
|
172
|
+
else # \uXXXX
|
173
|
+
bytes = ''
|
174
|
+
i = 0
|
175
|
+
while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
|
176
|
+
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
|
177
|
+
i += 1
|
178
|
+
end
|
179
|
+
JSON::UTF16toUTF8.iconv(bytes)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
if string.respond_to?(:force_encoding)
|
183
|
+
string.force_encoding(Encoding::UTF_8)
|
184
|
+
end
|
185
|
+
string
|
186
|
+
else
|
187
|
+
UNPARSED
|
188
|
+
end
|
189
|
+
rescue Iconv::Failure => e
|
190
|
+
raise GeneratorError, "Caught #{e.class}: #{e}"
|
191
|
+
end
|
192
|
+
|
193
|
+
def parse_value
|
194
|
+
case
|
195
|
+
when scan(FLOAT)
|
196
|
+
Float(self[1])
|
197
|
+
when scan(INTEGER)
|
198
|
+
Integer(self[1])
|
199
|
+
when scan(TRUE)
|
200
|
+
true
|
201
|
+
when scan(FALSE)
|
202
|
+
false
|
203
|
+
when scan(NULL)
|
204
|
+
nil
|
205
|
+
when (string = parse_string) != UNPARSED
|
206
|
+
string
|
207
|
+
when scan(ARRAY_OPEN)
|
208
|
+
@current_nesting += 1
|
209
|
+
ary = parse_array
|
210
|
+
@current_nesting -= 1
|
211
|
+
ary
|
212
|
+
when scan(OBJECT_OPEN)
|
213
|
+
@current_nesting += 1
|
214
|
+
obj = parse_object
|
215
|
+
@current_nesting -= 1
|
216
|
+
obj
|
217
|
+
when @allow_nan && scan(NAN)
|
218
|
+
NaN
|
219
|
+
when @allow_nan && scan(INFINITY)
|
220
|
+
Infinity
|
221
|
+
when @allow_nan && scan(MINUS_INFINITY)
|
222
|
+
MinusInfinity
|
223
|
+
else
|
224
|
+
UNPARSED
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def parse_array
|
229
|
+
raise NestingError, "nesting of #@current_nesting is too deep" if
|
230
|
+
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
231
|
+
result = @array_class.new
|
232
|
+
delim = false
|
233
|
+
until eos?
|
234
|
+
case
|
235
|
+
when (value = parse_value) != UNPARSED
|
236
|
+
delim = false
|
237
|
+
result << value
|
238
|
+
skip(IGNORE)
|
239
|
+
if scan(COLLECTION_DELIMITER)
|
240
|
+
delim = true
|
241
|
+
elsif match?(ARRAY_CLOSE)
|
242
|
+
;
|
243
|
+
else
|
244
|
+
raise ParserError, "expected ',' or ']' in array at '#{peek(20)}'!"
|
245
|
+
end
|
246
|
+
when scan(ARRAY_CLOSE)
|
247
|
+
if delim
|
248
|
+
raise ParserError, "expected next element in array at '#{peek(20)}'!"
|
249
|
+
end
|
250
|
+
break
|
251
|
+
when skip(IGNORE)
|
252
|
+
;
|
253
|
+
else
|
254
|
+
raise ParserError, "unexpected token in array at '#{peek(20)}'!"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
result
|
258
|
+
end
|
259
|
+
|
260
|
+
def parse_object
|
261
|
+
raise NestingError, "nesting of #@current_nesting is too deep" if
|
262
|
+
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
263
|
+
result = @object_class.new
|
264
|
+
delim = false
|
265
|
+
until eos?
|
266
|
+
case
|
267
|
+
when (string = parse_string) != UNPARSED
|
268
|
+
skip(IGNORE)
|
269
|
+
unless scan(PAIR_DELIMITER)
|
270
|
+
raise ParserError, "expected ':' in object at '#{peek(20)}'!"
|
271
|
+
end
|
272
|
+
skip(IGNORE)
|
273
|
+
unless (value = parse_value).equal? UNPARSED
|
274
|
+
result[@symbolize_names ? string.to_sym : string] = value
|
275
|
+
delim = false
|
276
|
+
skip(IGNORE)
|
277
|
+
if scan(COLLECTION_DELIMITER)
|
278
|
+
delim = true
|
279
|
+
elsif match?(OBJECT_CLOSE)
|
280
|
+
;
|
281
|
+
else
|
282
|
+
raise ParserError, "expected ',' or '}' in object at '#{peek(20)}'!"
|
283
|
+
end
|
284
|
+
else
|
285
|
+
raise ParserError, "expected value in object at '#{peek(20)}'!"
|
286
|
+
end
|
287
|
+
when scan(OBJECT_CLOSE)
|
288
|
+
if delim
|
289
|
+
raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
|
290
|
+
end
|
291
|
+
if @create_id and klassname = result[@create_id]
|
292
|
+
klass = JSON.deep_const_get klassname
|
293
|
+
break unless klass and klass.json_creatable?
|
294
|
+
result = klass.json_create(result)
|
295
|
+
end
|
296
|
+
break
|
297
|
+
when skip(IGNORE)
|
298
|
+
;
|
299
|
+
else
|
300
|
+
raise ParserError, "unexpected token in object at '#{peek(20)}'!"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
result
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'json/common'
|
2
|
+
require 'json/pure/parser'
|
3
|
+
require 'json/pure/generator'
|
4
|
+
|
5
|
+
module JSON
|
6
|
+
begin
|
7
|
+
require 'iconv'
|
8
|
+
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
9
|
+
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be') # :nodoc:
|
10
|
+
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
11
|
+
UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8') # :nodoc:
|
12
|
+
UTF8toUTF16.iconv('no bom')
|
13
|
+
rescue LoadError
|
14
|
+
raise MissingUnicodeSupport,
|
15
|
+
"iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions"
|
16
|
+
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
17
|
+
# Iconv doesn't support big endian utf-16. Let's try to hack this manually
|
18
|
+
# into the converters.
|
19
|
+
begin
|
20
|
+
old_verbose, $VERBSOSE = $VERBOSE, nil
|
21
|
+
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
22
|
+
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16') # :nodoc:
|
23
|
+
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
24
|
+
UTF8toUTF16 = Iconv.new('utf-16', 'utf-8') # :nodoc:
|
25
|
+
UTF8toUTF16.iconv('no bom')
|
26
|
+
if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
|
27
|
+
swapper = Class.new do
|
28
|
+
def initialize(iconv) # :nodoc:
|
29
|
+
@iconv = iconv
|
30
|
+
end
|
31
|
+
|
32
|
+
def iconv(string) # :nodoc:
|
33
|
+
result = @iconv.iconv(string)
|
34
|
+
JSON.swap!(result)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
UTF8toUTF16 = swapper.new(UTF8toUTF16) # :nodoc:
|
38
|
+
end
|
39
|
+
if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
|
40
|
+
swapper = Class.new do
|
41
|
+
def initialize(iconv) # :nodoc:
|
42
|
+
@iconv = iconv
|
43
|
+
end
|
44
|
+
|
45
|
+
def iconv(string) # :nodoc:
|
46
|
+
string = JSON.swap!(string.dup)
|
47
|
+
@iconv.iconv(string)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
UTF16toUTF8 = swapper.new(UTF16toUTF8) # :nodoc:
|
51
|
+
end
|
52
|
+
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
53
|
+
raise MissingUnicodeSupport, "iconv doesn't seem to support UTF-8/UTF-16 conversions"
|
54
|
+
ensure
|
55
|
+
$VERBOSE = old_verbose
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Swap consecutive bytes of _string_ in place.
|
60
|
+
def self.swap!(string) # :nodoc:
|
61
|
+
0.upto(string.size / 2) do |i|
|
62
|
+
break unless string[2 * i + 1]
|
63
|
+
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
64
|
+
end
|
65
|
+
string
|
66
|
+
end
|
67
|
+
|
68
|
+
# This module holds all the modules/classes that implement JSON's
|
69
|
+
# functionality in pure ruby.
|
70
|
+
module Pure
|
71
|
+
$DEBUG and warn "Using pure library for JSON."
|
72
|
+
JSON.parser = Parser
|
73
|
+
JSON.generator = Generator
|
74
|
+
end
|
75
|
+
|
76
|
+
JSON_LOADED = true
|
77
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
"A JSON payload should be an object or array, not a string."
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Extra value after close": true} "misplaced quoted value"
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Illegal expression": 1 + 2}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Illegal invocation": alert()}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Numbers cannot have leading zeroes": 013}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Numbers cannot be hex": 0x14}
|
@@ -0,0 +1 @@
|
|
1
|
+
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Missing colon" null}
|
@@ -0,0 +1 @@
|
|
1
|
+
["Unclosed array"
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Double colon":: null}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Comma instead of colon", null}
|
@@ -0,0 +1 @@
|
|
1
|
+
["Colon instead of comma": false]
|
@@ -0,0 +1 @@
|
|
1
|
+
["Bad value", truth]
|
@@ -0,0 +1 @@
|
|
1
|
+
['single quote']
|
@@ -0,0 +1 @@
|
|
1
|
+
["tab character in string "]
|
@@ -0,0 +1 @@
|
|
1
|
+
{unquoted_key: "keys must be quoted"}
|
@@ -0,0 +1 @@
|
|
1
|
+
["extra comma",]
|
@@ -0,0 +1 @@
|
|
1
|
+
["double extra comma",,]
|
@@ -0,0 +1 @@
|
|
1
|
+
[ , "<-- missing value"]
|
@@ -0,0 +1 @@
|
|
1
|
+
["Comma after the close"],
|
@@ -0,0 +1 @@
|
|
1
|
+
["Extra close"]]
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Extra comma": true,}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
[
|
2
|
+
"JSON Test Pattern pass1",
|
3
|
+
{"object with 1 member":["array with 1 element"]},
|
4
|
+
{},
|
5
|
+
[],
|
6
|
+
-42,
|
7
|
+
true,
|
8
|
+
false,
|
9
|
+
null,
|
10
|
+
{
|
11
|
+
"integer": 1234567890,
|
12
|
+
"real": -9876.543210,
|
13
|
+
"e": 0.123456789e-12,
|
14
|
+
"E": 1.234567890E+34,
|
15
|
+
"": 23456789012E666,
|
16
|
+
"zero": 0,
|
17
|
+
"one": 1,
|
18
|
+
"space": " ",
|
19
|
+
"quote": "\"",
|
20
|
+
"backslash": "\\",
|
21
|
+
"controls": "\b\f\n\r\t",
|
22
|
+
"slash": "/ & \/",
|
23
|
+
"alpha": "abcdefghijklmnopqrstuvwyz",
|
24
|
+
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
25
|
+
"digit": "0123456789",
|
26
|
+
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
27
|
+
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
|
28
|
+
"true": true,
|
29
|
+
"false": false,
|
30
|
+
"null": null,
|
31
|
+
"array":[ ],
|
32
|
+
"object":{ },
|
33
|
+
"address": "50 St. James Street",
|
34
|
+
"url": "http://www.JSON.org/",
|
35
|
+
"comment": "// /* <!-- --",
|
36
|
+
"# -- --> */": " ",
|
37
|
+
" s p a c e d " :[1,2 , 3
|
38
|
+
|
39
|
+
,
|
40
|
+
|
41
|
+
4 , 5 , 6 ,7 ],
|
42
|
+
"compact": [1,2,3,4,5,6,7],
|
43
|
+
"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
|
44
|
+
"quotes": "" \u0022 %22 0x22 034 "",
|
45
|
+
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
|
46
|
+
: "A key can be any string"
|
47
|
+
},
|
48
|
+
0.5 ,98.6
|
49
|
+
,
|
50
|
+
99.44
|
51
|
+
,
|
52
|
+
|
53
|
+
1066
|
54
|
+
|
55
|
+
|
56
|
+
,"rosebud"]
|
@@ -0,0 +1 @@
|
|
1
|
+
["Illegal backslash escape: \x15"]
|
@@ -0,0 +1 @@
|
|
1
|
+
["Illegal backslash escape: \'"]
|
@@ -0,0 +1 @@
|
|
1
|
+
["Illegal backslash escape: \017"]
|
@@ -0,0 +1 @@
|
|
1
|
+
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
@@ -0,0 +1 @@
|
|
1
|
+
["tab\ character\ in\ string\ "]
|