COMMAND DOCS avoid adding summary/since if they don't exist (#10252)

If summary or since is empty, we used to return NULL in
COMMAND DOCS. Currently all redis commands will have these
two fields.

But not for module command, summary and since are optional
for RM_SetCommandInfo. With the change in #10043, if a module
command doesn't have the summary or since, redis-cli will
crash (see #10250).

In this commit, COMMAND DOCS avoid adding summary or since
when they are missing.
This commit is contained in:
Binbin 2022-02-08 01:57:50 +08:00 committed by GitHub
parent b95beeb595
commit 7f4cca11dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -4437,7 +4437,9 @@ void addReplyCommandInfo(client *c, struct redisCommand *cmd) {
/* Output the representation of a Redis command. Used by the COMMAND DOCS. */
void addReplyCommandDocs(client *c, struct redisCommand *cmd) {
/* Count our reply len so we don't have to use deferred reply. */
long maplen = 3;
long maplen = 1;
if (cmd->summary) maplen++;
if (cmd->since) maplen++;
if (cmd->complexity) maplen++;
if (cmd->doc_flags) maplen++;
if (cmd->deprecated_since) maplen++;
@ -4447,12 +4449,16 @@ void addReplyCommandDocs(client *c, struct redisCommand *cmd) {
if (cmd->subcommands_dict) maplen++;
addReplyMapLen(c, maplen);
addReplyBulkCString(c, "summary");
addReplyBulkCString(c, cmd->summary);
addReplyBulkCString(c, "since");
addReplyBulkCString(c, cmd->since);
if (cmd->summary) {
addReplyBulkCString(c, "summary");
addReplyBulkCString(c, cmd->summary);
}
if (cmd->since) {
addReplyBulkCString(c, "since");
addReplyBulkCString(c, cmd->since);
}
/* Always have the group, for module commands the group is always "module". */
addReplyBulkCString(c, "group");
addReplyBulkCString(c, COMMAND_GROUP_STR[cmd->group]);

View File

@ -15,8 +15,8 @@ start_server {tags {"modules"}} {
set docs_reply [r command docs subcommands.bitarray]
set docs [dict create {*}[lindex $docs_reply 1]]
set subcmds_in_cmd_docs [dict create {*}[dict get $docs subcommands]]
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|get"] {summary {} since {} group module}
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|set"] {summary {} since {} group module}
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|get"] {group module}
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|set"] {group module}
}
test "Module pure-container command fails on arity error" {