From 503954cbd756954e51fd7e97e86982c913872a4f Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 13 Oct 2021 20:35:30 +0200 Subject: [PATCH] Handle parts of the command using incompatible encodings --- lib/redis/connection/command_helper.rb | 2 ++ test/client_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/redis/connection/command_helper.rb b/lib/redis/connection/command_helper.rb index 04b89113a..f14f90a87 100644 --- a/lib/redis/connection/command_helper.rb +++ b/lib/redis/connection/command_helper.rb @@ -12,11 +12,13 @@ def build_command(args) if i.is_a? Array i.each do |j| j = j.to_s + j = j.encoding == Encoding::BINARY ? j : j.b command << "$#{j.bytesize}" command << j end else i = i.to_s + i = i.encoding == Encoding::BINARY ? i : i.b command << "$#{i.bytesize}" command << i end diff --git a/test/client_test.rb b/test/client_test.rb index 30f7e2cff..b11c5ebb2 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -73,4 +73,13 @@ def resolve end assert_equal 'Error connecting to Redis on 127.0.0.5:999 (Errno::ECONNREFUSED)', error.message end + + def test_mixed_encoding + r.call("MSET", "fée", "\x00\xFF".b, "じ案".encode(Encoding::SHIFT_JIS), "\t".encode(Encoding::ASCII)) + assert_equal "\x00\xFF".b, r.call("GET", "fée") + assert_equal "\t", r.call("GET", "じ案".encode(Encoding::SHIFT_JIS)) + + r.call("SET", "\x00\xFF", "fée") + assert_equal "fée", r.call("GET", "\x00\xFF".b) + end end