null+****@clear*****
null+****@clear*****
2011年 8月 6日 (土) 14:27:42 JST
Kouhei Sutou 2011-08-06 05:27:42 +0000 (Sat, 06 Aug 2011)
New Revision: ce15ae180a4e1e8b06199f24b130805bbae41a59
Log:
accept '#' and '-' as a valid name characters. fixes #1043
And any valid characters except '_' can be used as the first character.
Modified files:
lib/db.c
lib/db.h
test/unit/core/test-command-table-create.c
test/unit/core/test-table.c
test/unit/http/test-http-schema.rb
Modified: lib/db.c (+6 -4)
===================================================================
--- lib/db.c 2011-08-05 15:54:41 +0000 (9fb28e3)
+++ lib/db.c 2011-08-06 05:27:42 +0000 (cd8ce35)
@@ -276,15 +276,17 @@ grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size)
{
int len;
const char *name_end = name + name_size;
- if (name < name_end &&
- (*name == GRN_DB_PSEUDO_COLUMN_PREFIX ||
- (unsigned int)(*name - '0') < 10u)) {
+ if (name_size > 0 &&
+ *name == GRN_DB_PSEUDO_COLUMN_PREFIX) {
return GRN_INVALID_ARGUMENT;
}
while (name < name_end) {
char c = *name;
if ((unsigned int)((c | 0x20) - 'a') >= 26u &&
- (unsigned int)(c - '0') >= 10u && c != '_') {
+ (unsigned int)(c - '0') >= 10u &&
+ c != '_' &&
+ c != '-' &&
+ c != '#') {
return GRN_INVALID_ARGUMENT;
}
if (!(len = grn_charlen(ctx, name, name_end))) { break; }
Modified: lib/db.h (+1 -1)
===================================================================
--- lib/db.h 2011-08-05 15:54:41 +0000 (a79435b)
+++ lib/db.h 2011-08-06 05:27:42 +0000 (7fc61b0)
@@ -349,7 +349,7 @@ grn_obj *grn_column_open(grn_ctx *ctx, grn_obj *table,
grn_rc grn_obj_rename(grn_ctx *ctx, const char *old_path, const char *new_path);
grn_rc grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size);
-#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) ERR(GRN_INVALID_ARGUMENT, "%s: name can't start with '%c' and 0-9, and contains only 0-9, A-Z, a-z, or _: <%.*s>", error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
+#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) ERR(GRN_INVALID_ARGUMENT, "%s: name can't start with '%c' and contains only 0-9, A-Z, a-z, #, - or _: <%.*s>", error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
#define GRN_DB_P(s) ((s) && ((grn_db *)s)->obj.header.type == GRN_DB)
#define GRN_DB_PERSISTENT_P(s) (((grn_db *)s)->specs)
Modified: test/unit/core/test-command-table-create.c (+2 -2)
===================================================================
--- test/unit/core/test-command-table-create.c 2011-08-05 15:54:41 +0000 (549a713)
+++ test/unit/core/test-command-table-create.c 2011-08-06 05:27:42 +0000 (8364e8c)
@@ -82,7 +82,7 @@ test_invalid_name(void)
grn_test_assert_send_command_error(
context,
GRN_INVALID_ARGUMENT,
- "[table][create]: name can't start with '_' and 0-9, "
- "and contains only 0-9, A-Z, a-z, or _: <_Users>",
+ "[table][create]: name can't start with '_' and "
+ "contains only 0-9, A-Z, a-z, #, - or _: <_Users>",
"table_create _Users");
}
Modified: test/unit/core/test-table.c (+40 -6)
===================================================================
--- test/unit/core/test-table.c 2011-08-05 15:54:41 +0000 (a50d192)
+++ test/unit/core/test-table.c 2011-08-06 05:27:42 +0000 (8e36ef7)
@@ -33,6 +33,8 @@ void test_temporary_table_add(gpointer data);
void data_array_sort(void);
void test_array_sort(gpointer data);
void test_nonexistent_column(void);
+void data_create_with_valid_name(void);
+void test_create_with_valid_name(gpointer data);
void data_create_with_invalid_name(void);
void test_create_with_invalid_name(gpointer data);
void test_array_truncate(void);
@@ -351,16 +353,50 @@ test_nonexistent_column(void)
}
void
-data_create_with_invalid_name(void)
+data_create_with_valid_name(void)
{
#define ADD_DATUM(label, name) \
gcut_add_datum(label, \
"name", G_TYPE_STRING, name, \
NULL)
- ADD_DATUM("start with '_'", "_users");
ADD_DATUM("start with number", "0table");
ADD_DATUM("include '-'", "table-name");
+
+#define ADD_DATUM_VALID_CHARACTER(name) \
+ ADD_DATUM(name, name)
+
+ ADD_DATUM_VALID_CHARACTER("#");
+ ADD_DATUM_VALID_CHARACTER("-");
+
+#undef ADD_DATUM_INVALID_CHARACTER
+
+#undef ADD_DATUM
+}
+
+void
+test_create_with_valid_name(gpointer data)
+{
+ grn_obj *table;
+ const gchar *table_name;
+
+ table_name = gcut_data_get_string(data, "name");
+ table = grn_table_create(context, table_name, strlen(table_name),
+ NULL,
+ GRN_OBJ_TABLE_NO_KEY | GRN_OBJ_PERSISTENT,
+ NULL, NULL);
+ grn_test_assert_context(context);
+}
+
+void
+data_create_with_invalid_name(void)
+{
+#define ADD_DATUM(label, name) \
+ gcut_add_datum(label, \
+ "name", G_TYPE_STRING, name, \
+ NULL)
+
+ ADD_DATUM("start with '_'", "_users");
ADD_DATUM("include a space", "table name");
ADD_DATUM("space", " ");
@@ -369,7 +405,6 @@ data_create_with_invalid_name(void)
ADD_DATUM_INVALID_CHARACTER("!");
ADD_DATUM_INVALID_CHARACTER("\"");
- ADD_DATUM_INVALID_CHARACTER("#");
ADD_DATUM_INVALID_CHARACTER("$");
ADD_DATUM_INVALID_CHARACTER("%");
ADD_DATUM_INVALID_CHARACTER("&");
@@ -379,7 +414,6 @@ data_create_with_invalid_name(void)
ADD_DATUM_INVALID_CHARACTER("*");
ADD_DATUM_INVALID_CHARACTER("+");
ADD_DATUM_INVALID_CHARACTER(",");
- ADD_DATUM_INVALID_CHARACTER("-");
ADD_DATUM_INVALID_CHARACTER(".");
ADD_DATUM_INVALID_CHARACTER("/");
ADD_DATUM_INVALID_CHARACTER(":");
@@ -414,12 +448,12 @@ test_create_with_invalid_name(gpointer data)
table_name = gcut_data_get_string(data, "name");
table = grn_table_create(context, table_name, strlen(table_name),
NULL,
- GRN_OBJ_TABLE_NO_KEY,
+ GRN_OBJ_TABLE_NO_KEY | GRN_OBJ_PERSISTENT,
NULL, NULL);
grn_test_assert_error(
GRN_INVALID_ARGUMENT,
cut_take_printf("[table][create]: name can't start with '_' and "
- "0-9, and contains only 0-9, A-Z, a-z, or _: <%s>",
+ "contains only 0-9, A-Z, a-z, #, - or _: <%s>",
table_name),
context);
}
Modified: test/unit/http/test-http-schema.rb (+6 -6)
===================================================================
--- test/unit/http/test-http-schema.rb 2011-08-05 15:54:41 +0000 (6d0b675)
+++ test/unit/http/test-http-schema.rb 2011-08-06 05:27:42 +0000 (6ae6e7b)
@@ -200,8 +200,8 @@ class HTTPSchemaTest < Test::Unit::TestCase
response = get(command_path(:table_create, :name => "mori.daijiro"))
assert_error_response(Result::INVALID_ARGUMENT,
"[table][create]: " +
- "name can't start with '_' and 0-9, " +
- "and contains only 0-9, A-Z, a-z, or _: " +
+ "name can't start with '_' " +
+ "and contains only 0-9, A-Z, a-z, #, - or _: " +
"<mori.daijiro>",
response,
:content_type => "application/json")
@@ -211,8 +211,8 @@ class HTTPSchemaTest < Test::Unit::TestCase
response = get(command_path(:table_create, :name => "_mori"))
assert_error_response(Result::INVALID_ARGUMENT,
"[table][create]: " +
- "name can't start with '_' and 0-9, " +
- "and contains only 0-9, A-Z, a-z, or _: " +
+ "name can't start with '_' " +
+ "and contains only 0-9, A-Z, a-z, #, - or _: " +
"<_mori>",
response,
:content_type => "application/json")
@@ -227,8 +227,8 @@ class HTTPSchemaTest < Test::Unit::TestCase
response = get(command_path(:table_create, :name => "daijiro:mori"))
assert_error_response(Result::INVALID_ARGUMENT,
"[table][create]: " +
- "name can't start with '_' and 0-9, " +
- "and contains only 0-9, A-Z, a-z, or _: " +
+ "name can't start with '_' " +
+ "and contains only 0-9, A-Z, a-z, #, - or _: " +
"<daijiro:mori>",
response,
:content_type => "application/json")