summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-01-05 12:34:04 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-01-05 12:34:04 -0800
commit15c6ab5602ea580010e439de272f95c9aae6b577 (patch)
treee146d0f00dd85fda10eb2eb6e932c9330c7a14b1 /spec
parente5294ab56f26ccb35338032f656ac2e7362b61f1 (diff)
downloadffi-yajl-15c6ab5602ea580010e439de272f95c9aae6b577.tar.gz
fix validate_utf8: false encoding coercion
the string we get back from ffi is tagged as ascii encoded by default, so we must force encode it first. then we don't want to convert from binary to utf-8 since that will wind up mangling all the utf-8 characters, we want to convert from utf-8 to utf-8 while replacing invalid characters.
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/encoder_spec.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index 91009f4..e7f17ce 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -180,6 +180,7 @@ describe "FFI_Yajl::Encoder" do
"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" },
+ "helmüt" => { "dir" => "/home/helmüt", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Hañs Helmüt" },
},
},
},
@@ -203,6 +204,11 @@ describe "FFI_Yajl::Encoder" do
it "returns valid utf8" do
expect( encoder.encode(ruby).valid_encoding? ).to be true
end
+
+ it "does not mangle valid utf8" do
+ json = encoder.encode(ruby)
+ expect(json).to match(/Hañs Helmüt/)
+ end
end
end
end