diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-19 22:22:13 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-19 22:22:13 -0800 |
commit | f5a670d49b26764dbe805f1a8ad03c9d106eafea (patch) | |
tree | c850922a7c3d53b976fe17307bb90c3c90184194 | |
parent | 207105a5432a7f613c65c1d390b18dd0b32de53f (diff) | |
download | ffi-yajl-f5a670d49b26764dbe805f1a8ad03c9d106eafea.tar.gz |
unicode fixes
-rw-r--r-- | lib/ffi_yajl/ffi/parser.rb | 8 | ||||
-rw-r--r-- | spec/ffi_yajl/parser_spec.rb | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb index 7d411a2..6674952 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -86,7 +86,9 @@ module FFI_Yajl 1 end @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen| - self.key = key.slice(0,keylen) + s = key.slice(0,keylen) + s.force_encoding('UTF-8') if defined? Encoding + self.key = s 1 end @end_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx| @@ -125,12 +127,12 @@ module FFI_Yajl yajl_handle = ::FFI_Yajl.yajl_alloc(callback_ptr, nil, nil) if ( stat = ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok ) # FIXME: dup the error and call yajl_free_error? - error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.length) + error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize) raise ::FFI_Yajl::ParseError.new(error) end if ( stat = FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok ) # FIXME: dup the error and call yajl_free_error? - error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.length) + error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize) raise ::FFI_Yajl::ParseError.new(error) end finished diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb index bb7c356..7c91a38 100644 --- a/spec/ffi_yajl/parser_spec.rb +++ b/spec/ffi_yajl/parser_spec.rb @@ -66,7 +66,13 @@ describe "FFI_Yajl::Parser" do json = '{"foo": 1.0973731568539e7 }' expect(parser.parse(json)).to eql({"foo" => 1.0973731568539e+7 }) end + end + context "when parsing unicode in hash keys" do + it "handles heavy metal umlauts in keys" do + json = '{"München": "Bayern"}' + expect(parser.parse(json)).to eql({"München" => "Bayern"}) + end end end |