yajl-ruby 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.codeclimate.yml +40 -0
- data/.travis.yml +3 -7
- data/LICENSE +21 -0
- data/examples/encoding/chunked_encoding.rb +1 -1
- data/examples/encoding/one_shot.rb +1 -1
- data/examples/encoding/to_an_io.rb +1 -1
- data/examples/http/twitter_search_api.rb +1 -1
- data/examples/http/twitter_stream_api.rb +1 -1
- data/examples/parsing/from_file.rb +1 -1
- data/examples/parsing/from_stdin.rb +1 -1
- data/examples/parsing/from_string.rb +1 -1
- data/ext/yajl/yajl_encode.c +2 -2
- data/lib/yajl.rb +2 -2
- data/lib/yajl/version.rb +1 -1
- data/spec/encoding/encoding_spec.rb +45 -45
- data/spec/global/global_spec.rb +10 -10
- data/spec/http/http_delete_spec.rb +15 -15
- data/spec/http/http_error_spec.rb +7 -8
- data/spec/http/http_get_spec.rb +17 -17
- data/spec/http/http_post_spec.rb +19 -19
- data/spec/http/http_put_spec.rb +16 -16
- data/spec/http/http_stream_options_spec.rb +4 -4
- data/spec/json_gem_compatibility/compatibility_spec.rb +70 -70
- data/spec/parsing/active_support_spec.rb +10 -10
- data/spec/parsing/chunked_spec.rb +18 -18
- data/spec/parsing/fixtures_spec.rb +8 -8
- data/spec/parsing/large_number_spec.rb +1 -1
- data/spec/parsing/one_off_spec.rb +22 -29
- data/tasks/rspec.rake +1 -1
- data/yajl-ruby.gemspec +2 -2
- metadata +7 -6
- data/MIT-LICENSE +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 731d0a5e71e781ff6061f6fda922f73c773ad0ee
|
4
|
+
data.tar.gz: c3a1f37875013458989cf34988bed786d58c7c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33df12d70c43f4599438ce478755967d174ce403fddc946dd5b5ca2e76723ba064fc10bb1185513927a230bdbbf2ebe479d1666632127bfcd4afe367ea24e646
|
7
|
+
data.tar.gz: 2d78f6564a3c14a17fc55187a1951b5a5fa2b263dff0f47fd8d6d6d377727771989bdcb9b68970b5995fb53449e0d4053cffc96412820525dec184074e68225c
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# This is a sample .codeclimate.yml configured for Engine analysis on Code
|
2
|
+
# Climate Platform. For an overview of the Code Climate Platform, see here:
|
3
|
+
# http://docs.codeclimate.com/article/300-the-codeclimate-platform
|
4
|
+
|
5
|
+
# Under the engines key, you can configure which engines will analyze your repo.
|
6
|
+
# Each key is an engine name. For each value, you need to specify enabled: true
|
7
|
+
# to enable the engine as well as any other engines-specific configuration.
|
8
|
+
|
9
|
+
# For more details, see here:
|
10
|
+
# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
|
11
|
+
|
12
|
+
# For a list of all available engines, see here:
|
13
|
+
# http://docs.codeclimate.com/article/296-engines-available-engines
|
14
|
+
|
15
|
+
engines:
|
16
|
+
# to turn on an engine, add it here and set enabled to `true`
|
17
|
+
# to turn off an engine, set enabled to `false` or remove it
|
18
|
+
rubocop:
|
19
|
+
enabled: true
|
20
|
+
|
21
|
+
# Engines can analyze files and report issues on them, but you can separately
|
22
|
+
# decide which files will receive ratings based on those issues. This is
|
23
|
+
# specified by path patterns under the ratings key.
|
24
|
+
|
25
|
+
# For more details see here:
|
26
|
+
# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
|
27
|
+
|
28
|
+
# Note: If the ratings key is not specified, this will result in a 0.0 GPA on your dashboard.
|
29
|
+
|
30
|
+
ratings:
|
31
|
+
paths:
|
32
|
+
- ext/**
|
33
|
+
- lib/**
|
34
|
+
|
35
|
+
# You can globally exclude files from being analyzed by any engine using the
|
36
|
+
# exclude_paths key.
|
37
|
+
|
38
|
+
#exclude_paths:
|
39
|
+
#- spec/**/*
|
40
|
+
#- vendor/**/*
|
data/.travis.yml
CHANGED
@@ -4,15 +4,11 @@ rvm:
|
|
4
4
|
- 1.9.2
|
5
5
|
- 1.9.3
|
6
6
|
- 2.0.0
|
7
|
-
- 2.1
|
8
|
-
- 2
|
7
|
+
- 2.1
|
8
|
+
- rbx-2
|
9
9
|
- ree
|
10
10
|
- ruby-head
|
11
|
-
- rbx-18mode
|
12
|
-
- rbx-19mode
|
13
11
|
before_install: gem install bundler --no-document
|
14
12
|
matrix:
|
15
13
|
allow_failures:
|
16
|
-
- rvm: rbx
|
17
|
-
- rvm: rbx-18mode
|
18
|
-
- rvm: rbx-19mode
|
14
|
+
- rvm: rbx-2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Brian Lopez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/ext/yajl/yajl_encode.c
CHANGED
@@ -162,8 +162,8 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
|
162
162
|
end+=3;
|
163
163
|
/* check if this is a surrogate */
|
164
164
|
if ((codepoint & 0xFC00) == 0xD800) {
|
165
|
-
|
166
|
-
|
165
|
+
end++;
|
166
|
+
if (str[end] == '\\' && str[end + 1] == 'u') {
|
167
167
|
unsigned int surrogate = 0;
|
168
168
|
hexToDigit(&surrogate, str + end + 2);
|
169
169
|
codepoint =
|
data/lib/yajl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'yajl/yajl'
|
2
2
|
|
3
3
|
# = Extras
|
4
|
-
# We're not going to load these
|
4
|
+
# We're not going to load these automatically, because you might not need them ;)
|
5
5
|
#
|
6
6
|
# require 'yajl/http_stream.rb' unless defined?(Yajl::HttpStream)
|
7
7
|
# require 'yajl/gzip.rb' unless defined?(Yajl::Gzip)
|
@@ -73,4 +73,4 @@ module Yajl
|
|
73
73
|
new(options).encode(obj, io, &block)
|
74
74
|
end
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|
data/lib/yajl/version.rb
CHANGED
@@ -37,7 +37,7 @@ describe "Yajl JSON encoder" do
|
|
37
37
|
hash2 = Yajl::Parser.parse(io)
|
38
38
|
io.close
|
39
39
|
input.close
|
40
|
-
hash.
|
40
|
+
expect(hash).to eq(hash2)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -58,7 +58,7 @@ describe "Yajl JSON encoder" do
|
|
58
58
|
Yajl::Parser.parse(reader.read)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
hash.
|
61
|
+
expect(hash).to eq(hash2)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -73,7 +73,7 @@ describe "Yajl JSON encoder" do
|
|
73
73
|
output = encoder.encode(hash)
|
74
74
|
hash2 = Yajl::Parser.parse(output)
|
75
75
|
input.close
|
76
|
-
hash.
|
76
|
+
expect(hash).to eq(hash2)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -91,7 +91,7 @@ describe "Yajl JSON encoder" do
|
|
91
91
|
end
|
92
92
|
hash2 = Yajl::Parser.parse(output)
|
93
93
|
input.close
|
94
|
-
hash.
|
94
|
+
expect(hash).to eq(hash2)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -103,7 +103,7 @@ describe "Yajl JSON encoder" do
|
|
103
103
|
encoder = Yajl::Encoder.new(:pretty => true, :indent => ' ')
|
104
104
|
encoder.encode(obj, io)
|
105
105
|
io.rewind
|
106
|
-
io.read.
|
106
|
+
expect(io.read).to eq(output)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should encode with :pretty turned on and a single space indent, and return a String" do
|
@@ -111,7 +111,7 @@ describe "Yajl JSON encoder" do
|
|
111
111
|
obj = {:foo => 1234}
|
112
112
|
encoder = Yajl::Encoder.new(:pretty => true, :indent => ' ')
|
113
113
|
output = encoder.encode(obj)
|
114
|
-
output.
|
114
|
+
expect(output).to eq(output)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should encode with :pretty turned on and a tab character indent, to an IO" do
|
@@ -121,7 +121,7 @@ describe "Yajl JSON encoder" do
|
|
121
121
|
encoder = Yajl::Encoder.new(:pretty => true, :indent => "\t")
|
122
122
|
encoder.encode(obj, io)
|
123
123
|
io.rewind
|
124
|
-
io.read.
|
124
|
+
expect(io.read).to eq(output)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should encode with :pretty turned on and a tab character indent, and return a String" do
|
@@ -129,7 +129,7 @@ describe "Yajl JSON encoder" do
|
|
129
129
|
obj = {:foo => 1234}
|
130
130
|
encoder = Yajl::Encoder.new(:pretty => true, :indent => "\t")
|
131
131
|
output = encoder.encode(obj)
|
132
|
-
output.
|
132
|
+
expect(output).to eq(output)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should encode with it's class method with :pretty and a tab character indent options set, to an IO" do
|
@@ -138,14 +138,14 @@ describe "Yajl JSON encoder" do
|
|
138
138
|
io = StringIO.new
|
139
139
|
Yajl::Encoder.encode(obj, io, :pretty => true, :indent => "\t")
|
140
140
|
io.rewind
|
141
|
-
io.read.
|
141
|
+
expect(io.read).to eq(output)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should encode with it's class method with :pretty and a tab character indent options set, and return a String" do
|
145
145
|
output = "{\n\t\"foo\": 1234\n}"
|
146
146
|
obj = {:foo => 1234}
|
147
147
|
output = Yajl::Encoder.encode(obj, :pretty => true, :indent => "\t")
|
148
|
-
output.
|
148
|
+
expect(output).to eq(output)
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should encode with it's class method with :pretty and a tab character indent options set, to a block" do
|
@@ -155,7 +155,7 @@ describe "Yajl JSON encoder" do
|
|
155
155
|
Yajl::Encoder.encode(obj, :pretty => true, :indent => "\t") do |json_str|
|
156
156
|
output = json_str
|
157
157
|
end
|
158
|
-
output.
|
158
|
+
expect(output).to eq(output)
|
159
159
|
end
|
160
160
|
|
161
161
|
it "should encode multiple objects into a single stream, to an IO" do
|
@@ -167,7 +167,7 @@ describe "Yajl JSON encoder" do
|
|
167
167
|
end
|
168
168
|
io.rewind
|
169
169
|
output = "{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}"
|
170
|
-
io.read.
|
170
|
+
expect(io.read).to eq(output)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should encode multiple objects into a single stream, and return a String" do
|
@@ -178,37 +178,37 @@ describe "Yajl JSON encoder" do
|
|
178
178
|
json_output << encoder.encode(obj)
|
179
179
|
end
|
180
180
|
output = "{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}{\"foo\":1234}"
|
181
|
-
json_output.
|
181
|
+
expect(json_output).to eq(output)
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should encode all map keys as strings" do
|
185
|
-
Yajl::Encoder.encode({1=>1}).
|
185
|
+
expect(Yajl::Encoder.encode({1=>1})).to eql("{\"1\":1}")
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should check for and call #to_json if it exists on custom objects" do
|
189
189
|
d = Dummy2.new
|
190
|
-
Yajl::Encoder.encode({:foo => d}).
|
190
|
+
expect(Yajl::Encoder.encode({:foo => d})).to eql('{"foo":{"hawtness":true}}')
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should encode a hash where the key and value can be symbols" do
|
194
|
-
Yajl::Encoder.encode({:foo => :bar}).
|
194
|
+
expect(Yajl::Encoder.encode({:foo => :bar})).to eql('{"foo":"bar"}')
|
195
195
|
end
|
196
196
|
|
197
197
|
it "should encode using a newline or nil terminator" do
|
198
|
-
Yajl::Encoder.new(:terminator => "\n").encode({:foo => :bar}).
|
199
|
-
Yajl::Encoder.new(:terminator => nil).encode({:foo => :bar}).
|
198
|
+
expect(Yajl::Encoder.new(:terminator => "\n").encode({:foo => :bar})).to eql("{\"foo\":\"bar\"}\n")
|
199
|
+
expect(Yajl::Encoder.new(:terminator => nil).encode({:foo => :bar})).to eql("{\"foo\":\"bar\"}")
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should encode using a newline or nil terminator, to an IO" do
|
203
203
|
s = StringIO.new
|
204
204
|
Yajl::Encoder.new(:terminator => "\n").encode({:foo => :bar}, s)
|
205
205
|
s.rewind
|
206
|
-
s.read.
|
206
|
+
expect(s.read).to eql("{\"foo\":\"bar\"}\n")
|
207
207
|
|
208
208
|
s = StringIO.new
|
209
209
|
Yajl::Encoder.new(:terminator => nil).encode({:foo => :bar}, s)
|
210
210
|
s.rewind
|
211
|
-
s.read.
|
211
|
+
expect(s.read).to eql("{\"foo\":\"bar\"}")
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should encode using a newline or nil terminator, using a block" do
|
@@ -217,7 +217,7 @@ describe "Yajl JSON encoder" do
|
|
217
217
|
s << chunk
|
218
218
|
end
|
219
219
|
s.rewind
|
220
|
-
s.read.
|
220
|
+
expect(s.read).to eql("{\"foo\":\"bar\"}\n")
|
221
221
|
|
222
222
|
s = StringIO.new
|
223
223
|
nilpassed = false
|
@@ -225,45 +225,45 @@ describe "Yajl JSON encoder" do
|
|
225
225
|
nilpassed = true if chunk.nil?
|
226
226
|
s << chunk
|
227
227
|
end
|
228
|
-
nilpassed.
|
228
|
+
expect(nilpassed).to be_truthy
|
229
229
|
s.rewind
|
230
|
-
s.read.
|
230
|
+
expect(s.read).to eql("{\"foo\":\"bar\"}")
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should not encode NaN" do
|
234
|
-
|
234
|
+
expect {
|
235
235
|
Yajl::Encoder.encode(0.0/0.0)
|
236
|
-
}.
|
236
|
+
}.to raise_error(Yajl::EncodeError)
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should not encode Infinity or -Infinity" do
|
240
|
-
|
240
|
+
expect {
|
241
241
|
Yajl::Encoder.encode(1.0/0.0)
|
242
|
-
}.
|
243
|
-
|
242
|
+
}.to raise_error(Yajl::EncodeError)
|
243
|
+
expect {
|
244
244
|
Yajl::Encoder.encode(-1.0/0.0)
|
245
|
-
}.
|
245
|
+
}.to raise_error(Yajl::EncodeError)
|
246
246
|
end
|
247
247
|
|
248
248
|
it "should encode with unicode chars in the key" do
|
249
249
|
hash = {"浅草" => "<- those are unicode"}
|
250
|
-
Yajl::Encoder.encode(hash).
|
250
|
+
expect(Yajl::Encoder.encode(hash)).to eql("{\"浅草\":\"<- those are unicode\"}")
|
251
251
|
end
|
252
252
|
|
253
253
|
if RUBY_VERSION =~ /^1.9/
|
254
254
|
it "should return a string encoded in utf-8 if Encoding.default_internal is nil" do
|
255
255
|
Encoding.default_internal = nil
|
256
256
|
hash = {"浅草" => "<- those are unicode"}
|
257
|
-
Yajl::Encoder.encode(hash).encoding.
|
257
|
+
expect(Yajl::Encoder.encode(hash).encoding).to eql(Encoding.find('utf-8'))
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should return a string encoded in utf-8 even if Encoding.default_internal *is* set" do
|
261
261
|
Encoding.default_internal = Encoding.find('utf-8')
|
262
262
|
hash = {"浅草" => "<- those are unicode"}
|
263
|
-
Yajl::Encoder.encode(hash).encoding.
|
263
|
+
expect(Yajl::Encoder.encode(hash).encoding).to eql(Encoding.default_internal)
|
264
264
|
Encoding.default_internal = Encoding.find('us-ascii')
|
265
265
|
hash = {"浅草" => "<- those are unicode"}
|
266
|
-
Yajl::Encoder.encode(hash).encoding.
|
266
|
+
expect(Yajl::Encoder.encode(hash).encoding).to eql(Encoding.find('utf-8'))
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
@@ -271,45 +271,45 @@ describe "Yajl JSON encoder" do
|
|
271
271
|
unsafe_encoder = Yajl::Encoder.new(:html_safe => false)
|
272
272
|
safe_encoder = Yajl::Encoder.new(:html_safe => true)
|
273
273
|
|
274
|
-
unsafe_encoder.encode("</script>").
|
275
|
-
safe_encoder.encode("</script>").
|
274
|
+
expect(unsafe_encoder.encode("</script>")).not_to eql("\"<\\/script>\"")
|
275
|
+
expect(safe_encoder.encode("</script>")).to eql("\"<\\/script>\"")
|
276
276
|
end
|
277
277
|
|
278
278
|
it "should default to *not* escaping / characters" do
|
279
279
|
unsafe_encoder = Yajl::Encoder.new
|
280
|
-
unsafe_encoder.encode("</script>").
|
280
|
+
expect(unsafe_encoder.encode("</script>")).not_to eql("\"<\\/script>\"")
|
281
281
|
end
|
282
282
|
|
283
283
|
it "return value of #to_json must be a string" do
|
284
|
-
|
284
|
+
expect {
|
285
285
|
Yajl::Encoder.encode(TheMindKiller.new)
|
286
|
-
}.
|
286
|
+
}.to raise_error(TypeError)
|
287
287
|
end
|
288
288
|
|
289
289
|
it "return value of #to_s must be a string" do
|
290
|
-
|
290
|
+
expect {
|
291
291
|
if TheMindKillerDuce.send(:method_defined?, :to_json)
|
292
292
|
TheMindKillerDuce.send(:undef_method, :to_json)
|
293
293
|
end
|
294
294
|
Yajl::Encoder.encode(TheMindKillerDuce.new)
|
295
|
-
}.
|
295
|
+
}.to raise_error(TypeError)
|
296
296
|
end
|
297
297
|
|
298
298
|
it "should raise an exception for deeply nested arrays" do
|
299
299
|
root = []
|
300
300
|
a = root
|
301
301
|
(Yajl::MAX_DEPTH + 1).times { |_| a << []; a = a[0] }
|
302
|
-
|
302
|
+
expect {
|
303
303
|
Yajl::Encoder.encode(root)
|
304
|
-
}.
|
304
|
+
}.to raise_error(Yajl::EncodeError)
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should raise an exception for deeply nested hashes" do
|
308
308
|
root = {}
|
309
309
|
a = root
|
310
310
|
(Yajl::MAX_DEPTH + 1).times { |_| a["a"] = {}; a = a["a"] }
|
311
|
-
|
311
|
+
expect {
|
312
312
|
Yajl::Encoder.encode(root)
|
313
|
-
}.
|
313
|
+
}.to raise_error(Yajl::EncodeError)
|
314
314
|
end
|
315
|
-
end
|
315
|
+
end
|