yajl-ruby 1.2.0 → 1.2.1
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.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/README.md +6 -0
- data/ext/yajl/extconf.rb +1 -1
- data/ext/yajl/yajl_ext.c +8 -9
- data/lib/yajl/version.rb +1 -1
- data/spec/json_gem_compatibility/compatibility_spec.rb +2 -2
- data/spec/parsing/active_support_spec.rb +2 -2
- data/spec/parsing/chunked_spec.rb +3 -3
- data/spec/parsing/fixtures_spec.rb +3 -3
- data/spec/parsing/large_number_spec.rb +60 -0
- data/spec/parsing/one_off_spec.rb +6 -1
- data/spec/spec_helper.rb +0 -3
- data/yajl-ruby.gemspec +3 -2
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17f8ce761c82a4625e4b55c33f7047c096912762
|
4
|
+
data.tar.gz: 14c6fa5ed9a57dda37e8e2191f49a1fd6353d323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a13ef5aad63d7b2ceff3a7db250eb03556f3ef3de4d12d5eabf67698c063b89e3964a062bbc25de0c88e5b7e4d25a6f5e3ed7b44bfe6c2bc864389e433375d
|
7
|
+
data.tar.gz: 3038b8ca0f7a587b8ddc20e7130f078b24fad9b3066d53e1aead28ef91d883c13996e5beaca3dd8b0c52b6ae9a12e116c5be89b3fac374ba62eb4a26869344da
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,12 @@ Go ahead and install it as usual:
|
|
25
25
|
gem install yajl-ruby
|
26
26
|
```
|
27
27
|
|
28
|
+
Or use your Gemfile:
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
gem 'yajl-ruby', require: 'yajl'
|
32
|
+
```
|
33
|
+
|
28
34
|
## Example of use
|
29
35
|
|
30
36
|
NOTE: I'm building up a collection of small examples in the examples (http://github.com/brianmario/yajl-ruby/tree/master/examples) folder.
|
data/ext/yajl/extconf.rb
CHANGED
data/ext/yajl/yajl_ext.c
CHANGED
@@ -275,7 +275,7 @@ static int yajl_found_boolean(void * ctx, int boolean) {
|
|
275
275
|
}
|
276
276
|
|
277
277
|
static int yajl_found_number(void * ctx, const char * numberVal, unsigned int numberLen) {
|
278
|
-
char buf
|
278
|
+
char* buf = (char*)malloc(numberLen + 1);
|
279
279
|
buf[numberLen] = 0;
|
280
280
|
memcpy(buf, numberVal, numberLen);
|
281
281
|
|
@@ -286,6 +286,7 @@ static int yajl_found_number(void * ctx, const char * numberVal, unsigned int nu
|
|
286
286
|
} else {
|
287
287
|
yajl_set_static_value(ctx, rb_cstr2inum(buf, 10));
|
288
288
|
}
|
289
|
+
free(buf);
|
289
290
|
return 1;
|
290
291
|
}
|
291
292
|
|
@@ -315,15 +316,13 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi
|
|
315
316
|
#endif
|
316
317
|
|
317
318
|
if (wrapper->symbolizeKeys) {
|
318
|
-
char buf[stringLen+1];
|
319
|
-
memcpy(buf, stringVal, stringLen);
|
320
|
-
buf[stringLen] = 0;
|
321
|
-
VALUE stringEncoded = rb_str_new2(buf);
|
322
319
|
#ifdef HAVE_RUBY_ENCODING_H
|
323
|
-
|
320
|
+
ID id = rb_intern3((const char *)stringVal, stringLen, utf8Encoding);
|
321
|
+
keyStr = ID2SYM(id);
|
322
|
+
#else
|
323
|
+
VALUE str = rb_str_new((const char *)stringVal, stringLen);
|
324
|
+
keyStr = rb_str_intern(str);
|
324
325
|
#endif
|
325
|
-
|
326
|
-
yajl_set_static_value(ctx, ID2SYM(rb_to_id(stringEncoded)));
|
327
326
|
} else {
|
328
327
|
keyStr = rb_str_new((const char *)stringVal, stringLen);
|
329
328
|
#ifdef HAVE_RUBY_ENCODING_H
|
@@ -332,8 +331,8 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi
|
|
332
331
|
keyStr = rb_str_export_to_enc(keyStr, default_internal_enc);
|
333
332
|
}
|
334
333
|
#endif
|
335
|
-
yajl_set_static_value(ctx, keyStr);
|
336
334
|
}
|
335
|
+
yajl_set_static_value(ctx, keyStr);
|
337
336
|
yajl_check_and_fire_callback(ctx);
|
338
337
|
return 1;
|
339
338
|
}
|
data/lib/yajl/version.rb
CHANGED
@@ -192,7 +192,7 @@ describe "JSON Gem compatability API" do
|
|
192
192
|
it "should be able to parse #{File.basename(name)} as an IO" do
|
193
193
|
lambda {
|
194
194
|
JSON.parse(StringIO.new(source))
|
195
|
-
}.should_not raise_error
|
195
|
+
}.should_not raise_error
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
@@ -200,7 +200,7 @@ describe "JSON Gem compatability API" do
|
|
200
200
|
it "should be able to parse #{File.basename(name)} as a string" do
|
201
201
|
lambda {
|
202
202
|
JSON.parse(source)
|
203
|
-
}.should_not raise_error
|
203
|
+
}.should_not raise_error
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
@@ -38,7 +38,7 @@ describe "ActiveSupport test cases" do
|
|
38
38
|
it "should be able to parse #{json} as an IO" do
|
39
39
|
lambda {
|
40
40
|
Yajl::Parser.parse(StringIO.new(json)).should == expected
|
41
|
-
}.should_not raise_error
|
41
|
+
}.should_not raise_error
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -46,7 +46,7 @@ describe "ActiveSupport test cases" do
|
|
46
46
|
it "should be able to parse #{json} as a string" do
|
47
47
|
lambda {
|
48
48
|
Yajl::Parser.parse(json).should == expected
|
49
|
-
}.should_not raise_error
|
49
|
+
}.should_not raise_error
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -67,7 +67,7 @@ describe "Chunked parser" do
|
|
67
67
|
@callback.should_receive(:call).exactly(430).times
|
68
68
|
lambda {
|
69
69
|
@parser.parse(json)
|
70
|
-
}.should_not raise_error
|
70
|
+
}.should_not raise_error
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should parse twitter_stream.json and fire callback 430 times, with a block as the callback" do
|
@@ -81,7 +81,7 @@ describe "Chunked parser" do
|
|
81
81
|
times += 1
|
82
82
|
end
|
83
83
|
times.should eql(430)
|
84
|
-
}.should_not raise_error
|
84
|
+
}.should_not raise_error
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should raise a Yajl::ParseError error if multiple JSON strings were found when no on_parse_complete callback assigned" do
|
@@ -93,4 +93,4 @@ describe "Chunked parser" do
|
|
93
93
|
@parser.parse(json)
|
94
94
|
}.should raise_error(Yajl::ParseError)
|
95
95
|
end
|
96
|
-
end
|
96
|
+
end
|
@@ -26,7 +26,7 @@ describe "Parsing JSON Fixtures" do
|
|
26
26
|
it "should be able to parse #{File.basename(name)} as an IO" do
|
27
27
|
lambda {
|
28
28
|
Yajl::Parser.parse(StringIO.new(source))
|
29
|
-
}.should_not raise_error
|
29
|
+
}.should_not raise_error
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ describe "Parsing JSON Fixtures" do
|
|
34
34
|
it "should be able to parse #{File.basename(name)} as a string" do
|
35
35
|
lambda {
|
36
36
|
Yajl::Parser.parse(source)
|
37
|
-
}.should_not raise_error
|
37
|
+
}.should_not raise_error
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Parsing very long text' do
|
4
|
+
shared_examples 'running script successfully' do |script|
|
5
|
+
def dup_pipe(parent_half, child_half, new_io)
|
6
|
+
parent_half.close
|
7
|
+
new_io.reopen(child_half)
|
8
|
+
child_half.close
|
9
|
+
end
|
10
|
+
|
11
|
+
def capture(cmd, stdin_data)
|
12
|
+
child_in, child_out, child_err = IO::pipe, IO::pipe, IO::pipe
|
13
|
+
|
14
|
+
child_pid = fork do
|
15
|
+
dup_pipe(child_in[1], child_in[0], STDIN)
|
16
|
+
dup_pipe(child_out[0], child_out[1], STDOUT)
|
17
|
+
dup_pipe(child_err[0], child_err[1], STDERR)
|
18
|
+
|
19
|
+
exec(cmd)
|
20
|
+
end
|
21
|
+
|
22
|
+
[
|
23
|
+
child_in[0],
|
24
|
+
child_out[1],
|
25
|
+
child_err[1],
|
26
|
+
].each(&:close)
|
27
|
+
|
28
|
+
child_in[1].write(stdin_data)
|
29
|
+
child_in[1].close
|
30
|
+
_, status = Process.waitpid2(child_pid)
|
31
|
+
|
32
|
+
return child_out[0].read, child_err[0].read, status
|
33
|
+
ensure
|
34
|
+
[
|
35
|
+
child_in[1],
|
36
|
+
child_out[0],
|
37
|
+
child_err[0],
|
38
|
+
].reject(&:closed?).each(&:close)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'runs successfully' do
|
42
|
+
out, err, status = capture('ruby', script)
|
43
|
+
[err, status.exitstatus].should eq(['', 0])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when parseing big floats' do
|
48
|
+
include_examples('running script successfully', <<-EOS)
|
49
|
+
require "yajl"
|
50
|
+
Yajl::Parser.parse('[0.' + '1' * 2**23 + ']')
|
51
|
+
EOS
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when parseing long hash key with symbolize_keys option' do
|
55
|
+
include_examples('running script successfully', <<-EOS)
|
56
|
+
require "yajl"
|
57
|
+
Yajl::Parser.parse('{"' + 'a' * 2**23 + '": 0}', :symbolize_keys => true)
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
end
|
@@ -20,7 +20,7 @@ describe "One-off JSON examples" do
|
|
20
20
|
json = StringIO.new('{"key": /* this is a comment */ "value"}')
|
21
21
|
lambda {
|
22
22
|
Yajl::Parser.parse(json, :allow_comments => true)
|
23
|
-
}.should_not raise_error
|
23
|
+
}.should_not raise_error
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should not parse invalid UTF8 with :check_utf8 set to true" do
|
@@ -67,6 +67,11 @@ describe "One-off JSON examples" do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
if RUBY_VERSION =~ /^1.9/
|
70
|
+
it "should encode non-ascii symbols in utf-8" do
|
71
|
+
parsed = Yajl::Parser.parse('{"曦": 1234}', :symbolize_keys => true)
|
72
|
+
parsed.keys.fetch(0).encoding.should eq(Encoding::UTF_8)
|
73
|
+
end
|
74
|
+
|
70
75
|
it "should return strings and hash keys in utf-8 if Encoding.default_internal is nil" do
|
71
76
|
Encoding.default_internal = nil
|
72
77
|
Yajl::Parser.parse('{"key": "value"}').keys.first.encoding.should eql(Encoding.find('utf-8'))
|
data/spec/spec_helper.rb
CHANGED
data/yajl-ruby.gemspec
CHANGED
@@ -3,6 +3,7 @@ require './lib/yajl/version'
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{yajl-ruby}
|
5
5
|
s.version = Yajl::VERSION
|
6
|
+
s.license = "MIT"
|
6
7
|
s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
|
7
8
|
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
8
9
|
s.email = %q{seniorlopez@gmail.com}
|
@@ -17,9 +18,9 @@ Gem::Specification.new do |s|
|
|
17
18
|
|
18
19
|
# tests
|
19
20
|
s.add_development_dependency 'rake-compiler', ">= 0.7.5"
|
20
|
-
s.add_development_dependency 'rspec', "
|
21
|
+
s.add_development_dependency 'rspec', "~> 2.14"
|
21
22
|
# benchmarks
|
22
|
-
s.add_development_dependency 'activesupport'
|
23
|
+
s.add_development_dependency 'activesupport', '~> 3.1.2'
|
23
24
|
s.add_development_dependency 'json'
|
24
25
|
end
|
25
26
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yajl-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Lopez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -29,30 +29,30 @@ dependencies:
|
|
29
29
|
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
34
|
+
version: '2.14'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.
|
41
|
+
version: '2.14'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: activesupport
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 3.1.2
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 3.1.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: json
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- spec/parsing/fixtures/pass2.json
|
219
219
|
- spec/parsing/fixtures/pass3.json
|
220
220
|
- spec/parsing/fixtures_spec.rb
|
221
|
+
- spec/parsing/large_number_spec.rb
|
221
222
|
- spec/parsing/one_off_spec.rb
|
222
223
|
- spec/rcov.opts
|
223
224
|
- spec/spec_helper.rb
|
@@ -225,7 +226,8 @@ files:
|
|
225
226
|
- tasks/rspec.rake
|
226
227
|
- yajl-ruby.gemspec
|
227
228
|
homepage: http://github.com/brianmario/yajl-ruby
|
228
|
-
licenses:
|
229
|
+
licenses:
|
230
|
+
- MIT
|
229
231
|
metadata: {}
|
230
232
|
post_install_message:
|
231
233
|
rdoc_options: []
|
@@ -332,6 +334,7 @@ test_files:
|
|
332
334
|
- spec/parsing/fixtures/pass2.json
|
333
335
|
- spec/parsing/fixtures/pass3.json
|
334
336
|
- spec/parsing/fixtures_spec.rb
|
337
|
+
- spec/parsing/large_number_spec.rb
|
335
338
|
- spec/parsing/one_off_spec.rb
|
336
339
|
- spec/rcov.opts
|
337
340
|
- spec/spec_helper.rb
|