-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic check to find duplicate option in the command. #667
base: unstable
Are you sure you want to change the base?
Generic check to find duplicate option in the command. #667
Conversation
Signed-off-by: Shivshankar-Reddy <[email protected]>
Signed-off-by: Shivshankar-Reddy <[email protected]>
Signed-off-by: Shivshankar-Reddy <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #667 +/- ##
============================================
+ Coverage 70.21% 70.26% +0.05%
============================================
Files 110 110
Lines 60069 60102 +33
============================================
+ Hits 42175 42231 +56
+ Misses 17894 17871 -23
|
@@ -3710,6 +3710,60 @@ int commandCheckArity(client *c, sds *err) { | |||
return 1; | |||
} | |||
|
|||
int findDuplicatesOptions(client *c, const char *token) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int findDuplicatesOptions(client *c, const char *token) { | |
int findDuplicateOptions(client *c, const char *token) { |
if (!findDuplicatesOptions(c, c->cmd->args[iter].subargs[subiter].token)) { | ||
if (err) { | ||
*err = sdsnew(NULL); | ||
*err = sdscatprintf(*err, "duplicate '%s' option for '%s' command", | ||
c->cmd->args[iter].subargs[subiter].token, c->cmd->fullname); | ||
} | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to perform an early exit on first duplicate or capture all the duplicate parameters?
} else { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
} else { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do we need this?
for (int j = 2, k = c->argc - 1; j <= k; j++, k--) { | ||
if (!strcasecmp(token, c->argv[j]->ptr)) { | ||
matched++; | ||
} | ||
if (j != k && !strcasecmp(token, c->argv[k]->ptr)) { | ||
matched++; | ||
} | ||
if (matched > 1) { | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need two pointers here? How about the following ?
int count = 0;
for (int i = 2; i < argc; i++) {
if (!strcasecmp(token, c->argv[i]->ptr)) {
count++;
if (count > 1) {
return 0;
}
}
}
int findDuplicatesOptions(client *c, const char *token) { | ||
int matched = 0; | ||
for (int j = 2, k = c->argc - 1; j <= k; j++, k--) { | ||
if (!strcasecmp(token, c->argv[j]->ptr)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we handle the case if another field has the same value as the token
?
This fixes #571 .
Added a generic check in processCommand as similar to arity check.
Will close #602 as it focuses on only few commands.