Fix semicolon in column name

Summary:
Special casing the last token when adding it to the named expression list.
Added a test to check this case.

Reviewers: mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1052
This commit is contained in:
Matija Santl 2017-12-12 15:37:21 +01:00
parent a8488ac497
commit 2758b35c08
2 changed files with 12 additions and 1 deletions
src/query/frontend
tests/unit

View File

@ -181,7 +181,7 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
jt != tokens.end() && (jt->second != "," || num_open_braces ||
num_open_parantheses || num_open_brackets) &&
jt->second != "order" && jt->second != "skip" &&
jt->second != "limit" && jt->second != "union";
jt->second != "limit" && jt->second != "union" && jt->second != ";";
++jt) {
if (jt->second == "(") {
++num_open_parantheses;

View File

@ -346,4 +346,15 @@ TEST(QueryStripper, QueryReturnMap) {
EXPECT_THAT(stripped.named_expressions(),
UnorderedElementsAre(Pair(2, "{a: 1, b: 'foo'}")));
}
TEST(QueryStripper, QuerySemicolonEndingQuery1) {
StrippedQuery stripped("RETURN 1;");
EXPECT_THAT(stripped.named_expressions(), UnorderedElementsAre(Pair(2, "1")));
}
TEST(QueryStripper, QuerySemicolonEndingQuery2) {
StrippedQuery stripped("RETURN 42 ;");
EXPECT_THAT(stripped.named_expressions(),
UnorderedElementsAre(Pair(2, "42")));
}
}