Skip to content

Commit

Permalink
Sanitize escape char in Transformer::transformSymbolicName
Browse files Browse the repository at this point in the history
Escaped symbol name from parser will be of
form "`Some.Value`". Therefore, we need to sanitize
it such that we don't store the symbol with
escape character.
  • Loading branch information
gaurav8297 committed Jun 6, 2023
1 parent e733a17 commit dcb0bdd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/include/parser/transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Transformer {
std::unique_ptr<Statement> transform();

private:
static constexpr std::string_view ESCAPE_SYMBOL_CHAR = "`";

std::unique_ptr<RegularQuery> transformQuery(CypherParser::OC_QueryContext& ctx);

std::unique_ptr<RegularQuery> transformRegularQuery(CypherParser::OC_RegularQueryContext& ctx);
Expand Down
9 changes: 8 additions & 1 deletion src/parser/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,14 @@ std::string Transformer::transformSymbolicName(CypherParser::OC_SymbolicNameCont
if (ctx.UnescapedSymbolicName()) {
return ctx.UnescapedSymbolicName()->getText();
} else if (ctx.EscapedSymbolicName()) {
return ctx.EscapedSymbolicName()->getText();
std::string escapedSymbolName = ctx.EscapedSymbolicName()->getText();

Check warning on line 917 in src/parser/transformer.cpp

View check run for this annotation

Codecov / codecov/patch

src/parser/transformer.cpp#L917

Added line #L917 was not covered by tests
// escapedSymbolName symbol will be of form "`Some.Value`". Therefore, we need to sanitize
// it such that we don't store the symbol with escape character.
if (escapedSymbolName.starts_with(ESCAPE_SYMBOL_CHAR) &
escapedSymbolName.ends_with(ESCAPE_SYMBOL_CHAR)) {
escapedSymbolName = escapedSymbolName.substr(1, escapedSymbolName.size() - 2);

Check warning on line 922 in src/parser/transformer.cpp

View check run for this annotation

Codecov / codecov/patch

src/parser/transformer.cpp#L920-L922

Added lines #L920 - L922 were not covered by tests
}
return escapedSymbolName;
} else {
assert(ctx.HexLetter());
return ctx.HexLetter()->getText();
Expand Down

0 comments on commit dcb0bdd

Please sign in to comment.