[libshumate] vector: Fix bug in filter expressions



commit ed305211349c4584c195af17443186df5ea99a7e
Author: James Westman <james jwestman net>
Date:   Tue Feb 22 00:12:52 2022 -0600

    vector: Fix bug in filter expressions
    
    Fixed a bug where lookup expressions sometimes weren't inserted where
    needed.

 shumate/vector/shumate-vector-expression-filter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/shumate/vector/shumate-vector-expression-filter.c 
b/shumate/vector/shumate-vector-expression-filter.c
index 401278a..d7a51ff 100644
--- a/shumate/vector/shumate-vector-expression-filter.c
+++ b/shumate/vector/shumate-vector-expression-filter.c
@@ -55,6 +55,7 @@ shumate_vector_expression_filter_from_json_array (JsonArray *array, GError **err
   g_autoptr(ShumateVectorExpressionFilter) self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
   JsonNode *op_node;
   const char *op;
+  gboolean lookup_first_arg = TRUE;
   int expect_exprs = -1;
   int expect_ge_exprs = -1;
 
@@ -94,11 +95,13 @@ shumate_vector_expression_filter_from_json_array (JsonArray *array, GError **err
     {
       self->type = EXPR_HAS;
       expect_exprs = 1;
+      lookup_first_arg = FALSE;
     }
   else if (g_strcmp0 ("!has", op) == 0)
     {
       self->type = EXPR_NOT_HAS;
       expect_exprs = 1;
+      lookup_first_arg = FALSE;
     }
   else if (g_strcmp0 ("in", op) == 0)
     {
@@ -175,11 +178,11 @@ shumate_vector_expression_filter_from_json_array (JsonArray *array, GError **err
       g_autoptr(ShumateVectorExpression) expr = NULL;
 
       if (i == 1
-          && expect_exprs == 2
+          && lookup_first_arg
           && JSON_NODE_HOLDS_VALUE (arg)
           && json_node_get_value_type (arg) == G_TYPE_STRING)
         {
-          /* If the first argument of 2-argument function is a string,
+          /* If the first argument of a function is a string,
            * convert it to a GET expression so we can do things like
            * ["==", "admin_level", 2] */
           g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]