Skip to content

Commit

Permalink
Fix newline handling in clang-query parser
Browse files Browse the repository at this point in the history
Don't prematurely remove characters from the end of the string
  • Loading branch information
steveire committed Dec 29, 2019
1 parent dc93540 commit 544f200
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-query/QueryParser.cpp
Expand Up @@ -250,7 +250,7 @@ QueryRef QueryParser::doParse() {
return completeMatcherExpression();

Diagnostics Diag;
auto MatcherSource = Line.trim();
auto MatcherSource = Line.ltrim();
auto OrigMatcherSource = MatcherSource;
Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(
MatcherSource, nullptr, &QS.NamedValues, &Diag);
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
Expand Up @@ -348,4 +348,12 @@ match callExpr

ASSERT_TRUE(isa<InvalidQuery>(Q));
EXPECT_EQ("1:1: Invalid token <NewLine> found when looking for a value.", cast<InvalidQuery>(Q)->ErrStr);

Q = parse("\nm parmVarDecl()\nlet someMatcher\n");

ASSERT_TRUE(isa<MatchQuery>(Q));
Q = parse(Q->RemainingContent);

ASSERT_TRUE(isa<InvalidQuery>(Q));
EXPECT_EQ("1:1: Invalid token <NewLine> found when looking for a value.", cast<InvalidQuery>(Q)->ErrStr);
}

0 comments on commit 544f200

Please sign in to comment.