Skip to content

Commit 7a510ed

Browse files
committed
Criteria: Only allow != and ~= operators for string fields
1 parent 1532df3 commit 7a510ed

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

criteria.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) {
312312
enum operator op = OP_EQUALS;
313313
char *key = token;
314314
char *value = strstr(key, "=");
315-
bool bare_key = !value;
316315

317316
if (*key == '\0') {
318317
return true;
@@ -350,8 +349,7 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) {
350349
// Otherwise, anything is fair game. This helps to return a better error
351350
// message.
352351

353-
// String fields can have bare_key, or not bare_key
354-
352+
// String fields that support all operators
355353
if (strcmp(key, "app-name") == 0) {
356354
criteria->spec.app_name = true;
357355
return assign_condition(&criteria->app_name, op, value);
@@ -370,7 +368,7 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) {
370368
} else if (strcmp(key, "body") == 0) {
371369
criteria->spec.body = true;
372370
return assign_condition(&criteria->body, op, value);
373-
} else if (!bare_key) {
371+
} else if (op == OP_EQUALS) {
374372
if (strcmp(key, "urgency") == 0) {
375373
if (!parse_urgency(value, &criteria->urgency)) {
376374
fprintf(stderr, "Invalid urgency value '%s'", value);
@@ -402,6 +400,15 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) {
402400
}
403401
}
404402

403+
if (op == OP_REGEX_MATCHES) {
404+
fprintf(stderr, "Invalid criteria field/operator '%s~='\n", key);
405+
return false;
406+
} else if (op == OP_NOT_EQUALS) {
407+
// TODO: Support != for boolean fields.
408+
fprintf(stderr, "Invalid criteria field/operator '%s!='\n", key);
409+
return false;
410+
}
411+
405412
if (strcmp(key, "actionable") == 0) {
406413
if (!parse_boolean(value, &criteria->actionable)) {
407414
fprintf(stderr, "Invalid value '%s' for boolean field '%s'\n",
@@ -435,11 +442,7 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) {
435442
criteria->spec.hidden = true;
436443
return true;
437444
} else {
438-
if (bare_key) {
439-
fprintf(stderr, "Invalid boolean criteria field '%s'\n", key);
440-
} else {
441-
fprintf(stderr, "Invalid criteria field '%s'\n", key);
442-
}
445+
fprintf(stderr, "Invalid criteria field '%s'\n", key);
443446
return false;
444447
}
445448

0 commit comments

Comments
 (0)