ffi-yajl 1.3.1-universal-java → 1.4.0-universal-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -8
- data/lib/ffi_yajl/encoder.rb +4 -2
- data/lib/ffi_yajl/ext.rb +4 -1
- data/lib/ffi_yajl/platform.rb +7 -0
- data/lib/ffi_yajl/version.rb +1 -1
- data/spec/ffi_yajl/encoder_spec.rb +27 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5f262f9836e1f9784d714d886b874f4398060a9
|
4
|
+
data.tar.gz: c42ccef5579b6e41b5c048c8956224af7f66fc14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c87092e496b407b3080d0d654df253057a6ef2f58acb76a47ed648095a0fd253c78ec3843dc1e837906a208fc9619f8a6a62001f612118631a4783469fe8b5
|
7
|
+
data.tar.gz: e6fdf6d4c17b576afcf9763b936acf6ea42edf65359a83ed5b38e5d1ba7df8080ae49c721bead6e15a725d2fcf524de0d280c46d14f2bfd889c93260c5c700ee
|
data/README.md
CHANGED
@@ -1,14 +1,40 @@
|
|
1
1
|
|
2
2
|
[![Build Status](https://travis-ci.org/opscode/ffi-yajl.png)](https://travis-ci.org/opscode/ffi-yajl) [![Code Climate](https://codeclimate.com/github/opscode/ffi-yajl.png)](https://codeclimate.com/github/opscode/ffi-yajl)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
# FFI YAJL
|
5
|
+
|
6
|
+
ffi-yajl is a Ruby adapter for the [yajl](http://lloyd.github.io/yajl/)
|
7
|
+
JSON parser/generator library. ffi-yajl supports multiple Ruby C
|
8
|
+
extension mechanisms, including both MRI native extensions and FFI in
|
9
|
+
order to be compatible with as many Ruby implementations as possible
|
10
|
+
while providing good performance where possible.
|
11
|
+
|
12
|
+
## Basic Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'ffi-yajl'
|
16
|
+
json_out = FFI_Yajl::Encoder.encode( { "foo" => [ "bar", "baz" ] } )
|
17
|
+
# => "{\"foo\":[\"bar\",\"baz\"]}"
|
18
|
+
data_in = FFI_Yajl::Parser.parse( json_out )
|
19
|
+
# => {"foo"=>["bar", "baz"]}
|
20
|
+
```
|
21
|
+
|
22
|
+
## Why This Instead of X?
|
23
|
+
|
24
|
+
yajl is the only JSON library we've found that has error messages that
|
25
|
+
meet our requirements. The stdlib json gem and oj (at the time we
|
26
|
+
started this project) have error messages like "invalid token at byte
|
27
|
+
1234," which are probably fine for server use, but in
|
28
|
+
[chef](https://github.com/chef/chef) we frequently deal with
|
29
|
+
user-written JSON documents, which means we need a good user experience
|
30
|
+
when encountering malformed JSON.
|
31
|
+
|
32
|
+
We previously used brianmario's
|
33
|
+
[yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we
|
34
|
+
wanted to be able to fallback to using FFI bindings to the C code (so we
|
35
|
+
could support non-MRI rubies) and we also needed some bug fixes in
|
36
|
+
yajl2, but the maintainer wasn't able to devote enough time to the
|
37
|
+
project to make these updates in a timeframe that worked for us.
|
12
38
|
|
13
39
|
## Thanks
|
14
40
|
|
@@ -17,3 +43,9 @@ pulled in from brianmario's existing yajl-ruby gem, particularly all the c exten
|
|
17
43
|
process of writing this would have been much more difficult without being able to draw heavily from already solved problems in
|
18
44
|
yajl-ruby.
|
19
45
|
|
46
|
+
## License
|
47
|
+
|
48
|
+
Given that this draws heavily from the yajl-ruby sources, and could be considered a derivative work, the MIT License from that
|
49
|
+
project has been preserved and this source code has deliberately not been dual licensed under Chef's typical Apache License.
|
50
|
+
See the [LICENSE](https://github.com/chef/ffi-yajl/blob/master/LICENSE) file in this project.
|
51
|
+
|
data/lib/ffi_yajl/encoder.rb
CHANGED
@@ -8,7 +8,7 @@ module FFI_Yajl
|
|
8
8
|
# initialization that we can do in pure ruby
|
9
9
|
yajl_gen_opts = {}
|
10
10
|
|
11
|
-
yajl_gen_opts[:yajl_gen_validate_utf8] = true
|
11
|
+
yajl_gen_opts[:yajl_gen_validate_utf8] = @opts[:validate_utf8] == false ? false : true
|
12
12
|
yajl_gen_opts[:yajl_gen_beautify] = false
|
13
13
|
yajl_gen_opts[:yajl_gen_indent_string] = " "
|
14
14
|
|
@@ -46,8 +46,10 @@ module FFI_Yajl
|
|
46
46
|
raise FFI_Yajl::EncodeError, "Invalid number: cannot encode Infinity, -Infinity, or NaN"
|
47
47
|
when 6 # yajl_gen_no_buf
|
48
48
|
raise FFI_Yajl::EncodeError, "YAJL internal error: yajl_gen_get_buf was called, but a print callback was specified, so no internal buffer is available"
|
49
|
+
when 7 # yajl_gen_invalid_string
|
50
|
+
raise FFI_Yajl::EncodeError, "Invalid UTF-8 string: cannot encode to UTF-8"
|
49
51
|
else
|
50
|
-
raise FFI_Yajl::EncodeError, "Unknown YAJL Error, please report this as a bug"
|
52
|
+
raise FFI_Yajl::EncodeError, "Unknown YAJL Error (#{status}), please report this as a bug"
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/ffi_yajl/ext.rb
CHANGED
@@ -4,14 +4,17 @@ require 'ffi_yajl/encoder'
|
|
4
4
|
require 'ffi_yajl/parser'
|
5
5
|
require 'ffi'
|
6
6
|
require 'libyajl2'
|
7
|
+
require 'ffi_yajl/platform'
|
7
8
|
|
8
9
|
module FFI_Yajl
|
10
|
+
extend FFI_Yajl::Platform
|
11
|
+
|
9
12
|
# FIXME: DRY with ffi_yajl/ffi.rb
|
10
13
|
# FIXME: extract map_library_name from FFI and stop requiring it at the top level
|
11
14
|
# so that the C-library can be installed without FFI
|
12
15
|
libname = ::FFI.map_library_name("yajl")
|
13
16
|
# awful windows patch, but there is an open issue to entirely replace FFI.map_library_name already
|
14
|
-
libname = "libyajl.so" if
|
17
|
+
libname = "libyajl.so" if windows?
|
15
18
|
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
16
19
|
libpath.gsub!(/dylib/, 'bundle')
|
17
20
|
libpath = ::FFI.map_library_name("yajl") unless File.exist?(libpath)
|
data/lib/ffi_yajl/version.rb
CHANGED
@@ -5,7 +5,9 @@ require 'date'
|
|
5
5
|
|
6
6
|
describe "FFI_Yajl::Encoder" do
|
7
7
|
|
8
|
-
let(:
|
8
|
+
let(:options) { {} }
|
9
|
+
|
10
|
+
let(:encoder) { FFI_Yajl::Encoder.new(options) }
|
9
11
|
|
10
12
|
it "encodes hashes in keys as strings", :ruby_gte_193 => true do
|
11
13
|
ruby = { {'a' => 'b'} => 2 }
|
@@ -146,4 +148,28 @@ describe "FFI_Yajl::Encoder" do
|
|
146
148
|
end
|
147
149
|
end
|
148
150
|
|
151
|
+
context "when encoding invalid utf-8" do
|
152
|
+
ruby = {
|
153
|
+
"automatic"=>{
|
154
|
+
"etc"=>{
|
155
|
+
"passwd"=>{
|
156
|
+
"root"=>{"dir"=>"/root", "gid"=>0, "uid"=>0, "shell"=>"/bin/sh", "gecos"=>"Elan Ruusam\xc3\xa4e"},
|
157
|
+
"glen"=>{"dir"=>"/home/glen", "gid"=>500, "uid"=>500, "shell"=>"/bin/bash", "gecos"=>"Elan Ruusam\xE4e"},
|
158
|
+
}
|
159
|
+
},
|
160
|
+
},
|
161
|
+
}
|
162
|
+
|
163
|
+
it "raises an error on invalid json" do
|
164
|
+
expect{ encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, "Invalid UTF-8 string: cannot encode to UTF-8")
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when validate_utf8 is off" do
|
168
|
+
let(:options) { { :validate_utf8 => false } }
|
169
|
+
|
170
|
+
it "does not raise an error" do
|
171
|
+
expect{ encoder.encode(ruby) }.not_to raise_error
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
149
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-yajl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: universal-java
|
6
6
|
authors:
|
7
7
|
- Lamont Granquist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/ffi_yajl/ffi/parser.rb
|
155
155
|
- lib/ffi_yajl/json_gem.rb
|
156
156
|
- lib/ffi_yajl/parser.rb
|
157
|
+
- lib/ffi_yajl/platform.rb
|
157
158
|
- lib/ffi_yajl/version.rb
|
158
159
|
- spec/ffi_yajl/encoder_spec.rb
|
159
160
|
- spec/ffi_yajl/json_gem_spec.rb
|
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
requirements: []
|
181
182
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.4.3
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: Ruby FFI wrapper around YAJL 2.x
|