Skip to content

Commit

Permalink
check that brackets are properly balanced in a type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Sep 28, 2020
1 parent ddeb031 commit c027802
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clickhouse/types/type_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ bool TypeParser::Parse(TypeAst* type) {
type_ = &type_->elements.back();
break;
case Token::EOS:
// Ubalanced braces, brackets, etc is an error.
if (open_elements_.size() != 1) {
return false;
}
return true;
case Token::Invalid:
return false;
Expand Down
9 changes: 9 additions & 0 deletions ut/columns_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <clickhouse/columns/array.h>
#include <clickhouse/columns/date.h>
#include <clickhouse/columns/enum.h>
#include <clickhouse/columns/factory.h>
#include <clickhouse/columns/nullable.h>
#include <clickhouse/columns/numeric.h>
#include <clickhouse/columns/string.h>
Expand Down Expand Up @@ -169,3 +170,11 @@ TEST(ColumnsCase, UUIDSlice) {
ASSERT_EQ(sub->At(0), UInt128(0x84b9f24bc26b49c6llu, 0xa03b4ab723341951llu));
ASSERT_EQ(sub->At(1), UInt128(0x3507213c178649f9llu, 0x9faf035d662f60aellu));
}

TEST(ColumnsCase, UnmatchedBrackets) {
ASSERT_NE(nullptr, CreateColumnByType("FixedString(10)"));
// When type string has unmatched brackets, CreateColumnByType must return nullptr.
ASSERT_EQ(nullptr, CreateColumnByType("FixedString(10"));
ASSERT_EQ(nullptr, CreateColumnByType("Nullable(FixedString(10000"));
ASSERT_EQ(nullptr, CreateColumnByType("Nullable(FixedString(10000)"));
}

0 comments on commit c027802

Please sign in to comment.