[Groonga-commit] groonga/groonga at acc2478 [master] plugin string: fix a bug that inverted inspect buffer

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 1 10:46:55 JST 2016


Kouhei Sutou	2016-02-01 10:46:55 +0900 (Mon, 01 Feb 2016)

  New Revision: acc2478e60ae617be8c0ff27578d105957a5e193
  https://github.com/groonga/groonga/commit/acc2478e60ae617be8c0ff27578d105957a5e193

  Message:
    plugin string: fix a bug that inverted inspect buffer

  Added files:
    test/command/suite/select/function/string/string_length/invalid.expected
    test/command/suite/select/function/string/string_length/invalid.test
  Modified files:
    plugins/functions/string.c

  Modified: plugins/functions/string.c (+7 -3)
===================================================================
--- plugins/functions/string.c    2016-02-01 10:43:35 +0900 (d03fc62)
+++ plugins/functions/string.c    2016-02-01 10:46:55 +0900 (00448f5)
@@ -38,13 +38,17 @@ func_string_length(grn_ctx *ctx, int n_args, grn_obj **args,
   }
 
   target = args[0];
-  if (target->header.type != GRN_BULK) {
+  if (!(target->header.type == GRN_BULK &&
+        ((target->header.domain == GRN_DB_SHORT_TEXT) ||
+         (target->header.domain == GRN_DB_TEXT) ||
+         (target->header.domain == GRN_DB_LONG_TEXT)))) {
     grn_obj inspected;
 
     GRN_TEXT_INIT(&inspected, 0);
-    grn_inspect(ctx, target, &inspected);
+    grn_inspect(ctx, &inspected, target);
     GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
-                     "string_length(): target object must be bulk: <%.*s>",
+                     "string_length(): target object must be a text bulk: "
+                     "<%.*s>",
                      (int)GRN_TEXT_LEN(&inspected),
                      GRN_TEXT_VALUE(&inspected));
     GRN_OBJ_FIN(ctx, &inspected);

  Added: test/command/suite/select/function/string/string_length/invalid.expected (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/string/string_length/invalid.expected    2016-02-01 10:46:55 +0900 (8ea490f)
@@ -0,0 +1,42 @@
+plugin_register functions/string
+[[0,0.0,0.0],true]
+table_create Ages TABLE_HASH_KEY UInt8
+[[0,0.0,0.0],true]
+load --table Ages
+[
+{"_key": 29}
+]
+[[0,0.0,0.0],1]
+select Ages   --output_columns '_key, string_length(_key)'   --command_version 2
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "string_length(): target object must be a text bulk: <29>"
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_key",
+          "UInt8"
+        ],
+        [
+          "string_length",
+          "Object"
+        ]
+      ],
+      [
+        29,
+        "string_length(): target object must be a text bulk: <29>"
+      ]
+    ]
+  ]
+]
+#|e| string_length(): target object must be a text bulk: <29>

  Added: test/command/suite/select/function/string/string_length/invalid.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/string/string_length/invalid.test    2016-02-01 10:46:55 +0900 (8238cc2)
@@ -0,0 +1,12 @@
+plugin_register functions/string
+
+table_create Ages TABLE_HASH_KEY UInt8
+
+load --table Ages
+[
+{"_key": 29}
+]
+
+select Ages \
+  --output_columns '_key, string_length(_key)' \
+  --command_version 2
-------------- next part --------------
HTML����������������������������...
Download 



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