Skip to content

Commit

Permalink
Handle parts of the command using incompatible encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Oct 13, 2021
1 parent a3d8071 commit 503954c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/redis/connection/command_helper.rb
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/client_test.rb
Expand Up @@ -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

0 comments on commit 503954c

Please sign in to comment.