Skip to content

Commit

Permalink
Support /* */ comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jun 9, 2020
1 parent 67ee793 commit 91c03bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ protected virtual void CheckComposableSql([NotNull] string sql)
continue;
}

// SQL -- comment
if (c == '-')
{
if (NextChar() != '-')
Expand All @@ -459,6 +460,27 @@ protected virtual void CheckComposableSql([NotNull] string sql)
continue;
}

// SQL /* */ comment
if (c == '/')
{
if (NextChar() != '*')
{
throw new InvalidOperationException(RelationalStrings.FromSqlNonComposable);
}

while (true)
{
while (NextChar() != '*') { }

if (NextChar() == '/')
{
break;
}
}

continue;
}

if (char.ToLowerInvariant(c) == 's' &&
char.ToLowerInvariant(NextChar()) == 'e' &&
char.ToLowerInvariant(NextChar()) == 'l' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void CheckComposableSql_throws(string sql)
[InlineData("-- comment\n SELECT something")]
[InlineData("-- comment1\r\n --\t\rcomment2\r\nSELECT something")]
[InlineData("SELECT--\n1")]
[InlineData(" /* comment */ SELECT--\n1")]
[InlineData(" /* multi\n*line\r\n * comment */ \nSELECT--\n1")]
public void CheckComposableSql_does_not_throw(string sql)
=> CreateDummyQuerySqlGenerator().CheckComposableSql(sql);

Expand Down

0 comments on commit 91c03bb

Please sign in to comment.