diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-22 08:50:51 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-22 08:50:51 -0800 |
commit | 07e5fac2052a62be3a273b45e2c3f764254c6bb4 (patch) | |
tree | 38c8aca52033e574d90c44324d4583fda0793c5c /spec | |
parent | 36492e4bd8d1521945466c39515eb9a3a961a72d (diff) | |
download | ffi-yajl-07e5fac2052a62be3a273b45e2c3f764254c6bb4.tar.gz |
support turning off validate_utf8
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ffi_yajl/encoder_spec.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb index 5c9e6b7..c697411 100644 --- a/spec/ffi_yajl/encoder_spec.rb +++ b/spec/ffi_yajl/encoder_spec.rb @@ -5,7 +5,9 @@ require 'date' describe "FFI_Yajl::Encoder" do - let(:encoder) { FFI_Yajl::Encoder.new } + let(:options) { {} } + + let(:encoder) { FFI_Yajl::Encoder.new(options) } it "encodes hashes in keys as strings", :ruby_gte_193 => true do ruby = { {'a' => 'b'} => 2 } @@ -146,4 +148,28 @@ describe "FFI_Yajl::Encoder" do end end + context "when encoding invalid utf-8" do + ruby = { + "automatic"=>{ + "etc"=>{ + "passwd"=>{ + "root"=>{"dir"=>"/root", "gid"=>0, "uid"=>0, "shell"=>"/bin/sh", "gecos"=>"Elan Ruusam\xc3\xa4e"}, + "glen"=>{"dir"=>"/home/glen", "gid"=>500, "uid"=>500, "shell"=>"/bin/bash", "gecos"=>"Elan Ruusam\xE4e"}, + } + }, + }, + } + + it "raises and error on invalid json" do + expect{ encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, "Invalid UTF-8 string: cannot encode to UTF-8") + end + + context "when validate_utf8 is off" do + let(:options) { { :validate_utf8 => false } } + + it "does not raise an error" do + expect{ encoder.encode(ruby) }.not_to raise_error + end + end + end end |