Skip to content

Commit

Permalink
Merge pull request #26 from supercaracal/trim-verbatim-type-meta-chars
Browse files Browse the repository at this point in the history
Trim verbatim type header from bulk string reply
  • Loading branch information
byroot committed Jun 25, 2022
2 parents dcd7f3d + bc0e315 commit 79d4d89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hiredis-client/ext/redis_client/hiredis/hiredis_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ static void *reply_append(const redisReadTask *task, VALUE value) {
}

static void *reply_create_string(const redisReadTask *task, char *cstr, size_t len) {
if (len >= 4 && task->type == REDIS_REPLY_VERB) {
// Skip 4 bytes of verbatim type header.
cstr += 4;
len -= 4;
}

VALUE string = rb_external_str_new(cstr, len);
if (rb_enc_str_coderange(string) == ENC_CODERANGE_BROKEN) {
rb_enc_associate(string, rb_ascii8bit_encoding());
Expand Down
4 changes: 4 additions & 0 deletions test/shared/redis_client_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,8 @@ def test_custom_result_casting
assert_equal([false], @redis.pipelined { |p| p.call("SISMEMBER", "set", "unknown") { |m| m > 0 } })
assert_equal([false], @redis.multi { |p| p.call("SISMEMBER", "set", "unknown") { |m| m > 0 } })
end

def test_verbatim_string_reply
assert_equal("# Server", @redis.call("INFO")[0..7])
end
end

0 comments on commit 79d4d89

Please sign in to comment.