Skip to content
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

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

Shivshankar-Reddy
Copy link
Contributor

@Shivshankar-Reddy Shivshankar-Reddy commented Jun 18, 2024

This fixes #571 .

Added a generic check in processCommand as similar to arity check.
Will close #602 as it focuses on only few commands.

Signed-off-by: Shivshankar-Reddy <[email protected]>
Signed-off-by: Shivshankar-Reddy <[email protected]>
@Shivshankar-Reddy Shivshankar-Reddy marked this pull request as draft June 18, 2024 20:09
Signed-off-by: Shivshankar-Reddy <[email protected]>
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 84.84848% with 5 lines in your changes missing coverage. Please review.

Project coverage is 70.26%. Comparing base (be2c321) to head (595fad6).
Report is 28 commits behind head on unstable.

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     
Files Coverage Δ
src/server.c 88.50% <84.84%> (-0.04%) ⬇️

... and 9 files with indirect coverage changes

@Shivshankar-Reddy Shivshankar-Reddy marked this pull request as ready for review June 18, 2024 20:32
@hpatro hpatro added the breaking-change Indicates a possible backwards incompatible change label Jul 1, 2024
@@ -3710,6 +3710,60 @@ int commandCheckArity(client *c, sds *err) {
return 1;
}

int findDuplicatesOptions(client *c, const char *token) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int findDuplicatesOptions(client *c, const char *token) {
int findDuplicateOptions(client *c, const char *token) {

Comment on lines +3748 to +3755
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;
}
Copy link
Contributor

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?

Comment on lines +3756 to +3758
} else {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Comment on lines +3760 to +3762
} else {
continue;
}
Copy link
Contributor

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?

Comment on lines +3715 to +3724
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;
}
Copy link
Contributor

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)) {
Copy link
Contributor

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a possible backwards incompatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Duplicated arguments are accepted in ZINTER, ZUNION, and ZDIFF command
2 participants