Skip to content

Commit 69511df

Browse files
author
DvirDukhan
committed
fixed PR comments
1 parent ff81047 commit 69511df

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/command_parser.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
193193
bool is_input = false;
194194
bool is_output = false;
195195
bool timeout_set = false;
196+
bool inputs_done = false;
196197
size_t ninputs = 0, noutputs = 0;
197198
int varidic_start_pos = -1;
198199

@@ -207,17 +208,39 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
207208
continue;
208209
}
209210

210-
if (!strcasecmp(arg_string, "INPUTS") && !is_input) {
211+
if (!strcasecmp(arg_string, "INPUTS")) {
212+
if (inputs_done) {
213+
RAI_SetError(error, RAI_ESCRIPTRUN,
214+
"ERR Already encountered an INPUTS section in SCRIPTRUN");
215+
return REDISMODULE_ERR;
216+
}
217+
if (is_input) {
218+
RAI_SetError(error, RAI_ESCRIPTRUN,
219+
"ERR Already encountered an INPUTS keyword in SCRIPTRUN");
220+
return REDISMODULE_ERR;
221+
}
211222
is_input = true;
212223
is_output = false;
213224
continue;
214225
}
215-
if (!strcasecmp(arg_string, "OUTPUTS") && !is_output) {
226+
if (!strcasecmp(arg_string, "OUTPUTS")) {
227+
if (is_output) {
228+
RAI_SetError(error, RAI_ESCRIPTRUN,
229+
"ERR Already encountered an INPUTS keyword in SCRIPTRUN");
230+
return REDISMODULE_ERR;
231+
}
216232
is_input = false;
217233
is_output = true;
234+
inputs_done = true;
218235
continue;
219236
}
220237
if (!strcasecmp(arg_string, "$")) {
238+
if (!is_input) {
239+
RAI_SetError(
240+
error, RAI_ESCRIPTRUN,
241+
"ERR Encountered a variable size list of tensors outside of input section");
242+
return REDISMODULE_ERR;
243+
}
221244
if (varidic_start_pos > -1) {
222245
RAI_SetError(error, RAI_ESCRIPTRUN,
223246
"ERR Already encountered a variable size list of tensors");
@@ -227,15 +250,16 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
227250
continue;
228251
}
229252
// Parse argument name
230-
{
231-
RAI_HoldString(NULL, argv[argpos]);
232-
if (is_input) {
233-
ninputs++;
234-
*inkeys = array_append(*inkeys, argv[argpos]);
235-
} else {
236-
noutputs++;
237-
*outkeys = array_append(*outkeys, argv[argpos]);
238-
}
253+
RAI_HoldString(NULL, argv[argpos]);
254+
if (is_input) {
255+
ninputs++;
256+
*inkeys = array_append(*inkeys, argv[argpos]);
257+
} else if (is_output) {
258+
noutputs++;
259+
*outkeys = array_append(*outkeys, argv[argpos]);
260+
} else {
261+
RAI_SetError(error, RAI_ESCRIPTRUN, "ERR Unrecongnized parameter to SCRIPTRUN");
262+
return REDISMODULE_ERR;
239263
}
240264
}
241265
*variadic = varidic_start_pos;

0 commit comments

Comments
 (0)