null+****@clear*****
null+****@clear*****
2011年 5月 30日 (月) 18:13:31 JST
Kouhei Sutou 2011-05-30 09:13:31 +0000 (Mon, 30 May 2011)
New Revision: a772cc96254af39306b69bca6652b4b74060ec42
Log:
[load] add invalid table name check. refs #912
Modified files:
lib/db.c
test/unit/core/test-command-load.c
Modified: lib/db.c (+4 -0)
===================================================================
--- lib/db.c 2011-05-29 11:45:08 +0000 (755b6a8)
+++ lib/db.c 2011-05-30 09:13:31 +0000 (fd5c2df)
@@ -8249,6 +8249,10 @@ grn_load(grn_ctx *ctx, grn_content_type input_type,
if (table && table_len) {
grn_ctx_loader_clear(ctx);
loader->input_type = input_type;
+ if (grn_db_check_name(ctx, table, table_len)) {
+ GRN_DB_CHECK_NAME_ERR("[table][load]", table, table_len);
+ goto exit;
+ }
loader->table = grn_ctx_get(ctx, table, table_len);
if (!loader->table) {
ERR(GRN_INVALID_ARGUMENT, "nonexistent table: <%.*s>", table_len, table);
Modified: test/unit/core/test-command-load.c (+16 -1)
===================================================================
--- test/unit/core/test-command-load.c 2011-05-29 11:45:08 +0000 (ccf8ec2)
+++ test/unit/core/test-command-load.c 2011-05-30 09:13:31 +0000 (d0879c8)
@@ -37,6 +37,7 @@ void test_no_key_table(void);
void test_two_bigram_indexes_to_key(void);
void test_invalid_start_with_symbol(void);
void test_no_key_table_without_columns(void);
+void test_nonexistent_table_name(void);
void test_invalid_table_name(void);
static gchar *tmp_directory;
@@ -469,7 +470,7 @@ test_no_key_table_without_columns(void)
}
void
-test_invalid_table_name(void)
+test_nonexistent_table_name(void)
{
grn_test_assert_send_command_error(context,
GRN_INVALID_ARGUMENT,
@@ -479,3 +480,17 @@ test_invalid_table_name(void)
"[\"_key\": \"alice\"]\n"
"]");
}
+
+void
+test_invalid_table_name(void)
+{
+ grn_test_assert_send_command_error(
+ context,
+ GRN_INVALID_ARGUMENT,
+ "[table][load]: name can't start with '_' and 0-9, "
+ "and contains only 0-9, A-Z, a-z, or _: <_Users>",
+ "load --table _Users\n"
+ "[\n"
+ "[\"_key\": \"alice\"]\n"
+ "]");
+}