summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-01-22 08:50:51 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-22 08:50:51 -0800
commit07e5fac2052a62be3a273b45e2c3f764254c6bb4 (patch)
tree38c8aca52033e574d90c44324d4583fda0793c5c /spec
parent36492e4bd8d1521945466c39515eb9a3a961a72d (diff)
downloadffi-yajl-07e5fac2052a62be3a273b45e2c3f764254c6bb4.tar.gz
support turning off validate_utf8
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/encoder_spec.rb28
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