Skip to content

Commit 76c0890

Browse files
committed
Properly handling unbalanced braces in type name, added some tests
1 parent 5800488 commit 76c0890

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clickhouse/types/type_parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ bool TypeParser::Parse(TypeAst* type) {
139139
type_ = &type_->elements.back();
140140
break;
141141
case Token::EOS:
142+
{
143+
// Ubalanced braces, brackets, etc is an error.
144+
if (open_elements_.size() != 1)
145+
return false;
142146
return true;
147+
}
143148
case Token::Invalid:
144149
return false;
145150
}

ut/columns_ut.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,24 @@ TEST(ColumnsCase, LowCardinalityString_Save) {
261261
}
262262

263263
TEST(ColumnsCase, CreateSimpleAggregateFunction) {
264-
auto col = CreateColumnByType("SimpleAggregateFunction(funt, Int32");
264+
auto col = CreateColumnByType("SimpleAggregateFunction(funt, Int32)");
265265

266266
ASSERT_EQ("Int32", col->Type()->GetName());
267267
ASSERT_EQ(Type::Int32, col->Type()->GetCode());
268268
ASSERT_NE(nullptr, col->As<ColumnInt32>());
269269
}
270+
271+
272+
TEST(CreateColumnByType, UnmatchedBrackets) {
273+
// When type string has unmatched brackets, CreateColumnByType must return nullptr.
274+
ASSERT_EQ(nullptr, CreateColumnByType("FixedString(10"));
275+
ASSERT_EQ(nullptr, CreateColumnByType("Nullable(FixedString(10000"));
276+
ASSERT_EQ(nullptr, CreateColumnByType("Nullable(FixedString(10000)"));
277+
ASSERT_EQ(nullptr, CreateColumnByType("LowCardinality(Nullable(FixedString(10000"));
278+
ASSERT_EQ(nullptr, CreateColumnByType("LowCardinality(Nullable(FixedString(10000)"));
279+
ASSERT_EQ(nullptr, CreateColumnByType("LowCardinality(Nullable(FixedString(10000))"));
280+
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000"));
281+
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000)"));
282+
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000))"));
283+
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000)))"));
284+
}

0 commit comments

Comments
 (0)