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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b53bc9d9531949a27cb05b5877baa594e691362f
4
- data.tar.gz: dc3398cacd981441353db287b91fccdbf24266f3
3
+ metadata.gz: d5f262f9836e1f9784d714d886b874f4398060a9
4
+ data.tar.gz: c42ccef5579b6e41b5c048c8956224af7f66fc14
5
5
  SHA512:
6
- metadata.gz: 46f5f8029d0ef32c8c904f38093e422bfb7fd61078245c20f58997498d09df24a5ee212dda38cf745f97c3757709c0a229d41fa0eb6bc4e4787a18ff4cd1703f
7
- data.tar.gz: 5528506311181bc998ce071935157f74c027313fb43af831fae27253016f271c5ea8b66315959f885132dc7b1d45c5b7a1c4080b9ac9e729977df90b0b7deebe
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
- ## TODO
5
-
6
-
7
- ## BUILD NOTES
8
-
9
-
10
- ## KNOWN BUGS
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
+
@@ -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 libname == "yajl.dll"
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)
@@ -0,0 +1,7 @@
1
+ module FFI_Yajl
2
+ module Platform
3
+ def windows?
4
+ !!(RUBY_PLATFORM =~ /mswin|mingw|cygwin|windows/)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module FFI_Yajl
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -5,7 +5,9 @@ require 'date'
5
5
 
6
6
  describe "FFI_Yajl::Encoder" do
7
7
 
8
- let(:encoder) { FFI_Yajl::Encoder.new }
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.3.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: 2014-11-25 00:00:00.000000000 Z
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.2.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