未验证 提交 f2835a11 编写于 作者: J Joan Augsburger 提交者: GitHub

fix(griffin) - prevent invalid characters in column name when creating table...

fix(griffin) - prevent invalid characters in column name when creating table or adding column. Fixed #412 (#413)
上级 dcd8ebdd
......@@ -755,6 +755,10 @@ public class SqlCompiler implements Closeable {
CharSequence columnName = GenericLexer.immutableOf(tok);
if (!SqlKeywords.isValidColumnName(columnName)) {
throw SqlException.$(lexer.lastTokenPosition(), " new column name contains invalid characters");
}
tok = expectToken(lexer, "column type");
int type = ColumnType.columnTypeOf(tok);
......
......@@ -487,6 +487,10 @@ public final class SqlParser {
final CharSequence name = GenericLexer.immutableOf(GenericLexer.unquote(notTermTok(lexer)));
final int type = toColumnType(lexer, notTermTok(lexer));
if (!SqlKeywords.isValidColumnName(name)) {
throw SqlException.$(position, " new column name contains invalid characters");
}
if (!model.addColumn(name, type, configuration.getDefaultSymbolCapacity())) {
throw SqlException.$(position, "Duplicate column");
}
......
......@@ -52,6 +52,21 @@ public class AlterTableAddColumnTest extends AbstractGriffinTest {
assertFailure("alter table x add column abc int k", 33, "',' expected");
}
@Test
public void testAddBadColumnNameBackSlash() throws Exception {
assertFailure("alter table x add column \\", 25, "new column name contains invalid characters");
}
@Test
public void testAddBadColumnNameDot() throws Exception {
assertFailure("alter table x add column .", 25, "new column name contains invalid characters");
}
@Test
public void testAddBadColumnNameFwdSlash() throws Exception {
assertFailure("alter table x add column /", 25, "new column name contains invalid characters");
}
@Test
public void testAddBusyTable() throws Exception {
assertMemoryLeak(() -> {
......
......@@ -2328,6 +2328,16 @@ public class SqlCompilerTest extends AbstractGriffinTest {
"partition by MONTH");
}
@Test
public void testColumnNameWithDot() throws Exception {
assertFailure(27, "new column name contains invalid characters",
"create table x (" +
"t TIMESTAMP, " +
"`bool.flag` BOOLEAN) " +
"timestamp(t) " +
"partition by MONTH");
}
@Test
public void testEmptyQuery() {
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册