[Groonga-commit] groonga/groonga at a925832 [master] cast_loose: add the 1st argument validation

Back to archive index
Kouhei Sutou null+****@clear*****
Thu Oct 11 15:30:37 JST 2018


Kouhei Sutou	2018-10-11 15:30:37 +0900 (Thu, 11 Oct 2018)

  Revision: a92583234db3364c84ba43d452a4fddbd5f5f222
  https://github.com/groonga/groonga/commit/a92583234db3364c84ba43d452a4fddbd5f5f222

  Message:
    cast_loose: add the 1st argument validation

  Added files:
    test/command/suite/select/function/cast_loose/invalid/not_type.expected
    test/command/suite/select/function/cast_loose/invalid/not_type.test
  Modified files:
    lib/proc/proc_cast.c

  Modified: lib/proc/proc_cast.c (+13 -1)
===================================================================
--- lib/proc/proc_cast.c    2018-10-11 15:27:22 +0900 (c13e555d6)
+++ lib/proc/proc_cast.c    2018-10-11 15:30:37 +0900 (d26bcb15d)
@@ -39,10 +39,22 @@ func_cast_loose(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_dat
   }
 
   type = args[0];
+  if (!grn_obj_is_type(ctx, type)) {
+    grn_obj inspected;
+    GRN_TEXT_INIT(&inspected, 0);
+    grn_inspect(ctx, &inspected, type);
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "cast_loose(): the first argument must be type: <%.*s>",
+                     (int)GRN_TEXT_LEN(&inspected),
+                     GRN_TEXT_VALUE(&inspected));
+    GRN_OBJ_FIN(ctx, &inspected);
+    return NULL;
+  }
+  type_id = grn_obj_id(ctx, type);
+
   value = args[1];
   default_value = args[2];
 
-  type_id = grn_obj_id(ctx, type);
   casted_value = grn_plugin_proc_alloc(ctx, user_data, type_id, 0);
 
   rc = grn_obj_cast(ctx, value, casted_value, GRN_FALSE);

  Added: test/command/suite/select/function/cast_loose/invalid/not_type.expected (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/cast_loose/invalid/not_type.expected    2018-10-11 15:30:37 +0900 (ca7caf416)
@@ -0,0 +1,40 @@
+table_create Data TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+load --table Data
+[
+{"_key": "100"}
+]
+[[0,0.0,0.0],1]
+select Data --output_columns '_key, cast_loose("AAA", _key, 29)'
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "cast_loose(): the first argument must be type: <\"AAA\">"
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "cast_loose",
+          null
+        ]
+      ],
+      [
+        "100",
+        "cast_loose(): the first argument must be type: <\"AAA\">"
+      ]
+    ]
+  ]
+]
+#|e| cast_loose(): the first argument must be type: <"AAA">

  Added: test/command/suite/select/function/cast_loose/invalid/not_type.test (+6 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/cast_loose/invalid/not_type.test    2018-10-11 15:30:37 +0900 (523148e6a)
@@ -0,0 +1,6 @@
+table_create Data TABLE_HASH_KEY ShortText
+load --table Data
+[
+{"_key": "100"}
+]
+select Data --output_columns '_key, cast_loose("AAA", _key, 29)'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181011/28913f14/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index