From 15c6ab5602ea580010e439de272f95c9aae6b577 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 5 Jan 2016 12:34:04 -0800 Subject: 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. --- spec/ffi_yajl/encoder_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') 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 -- cgit v1.2.1