Skip to content

Commit 2252f95

Browse files
authored
Fixed: Parenthesis around an "In" expression raise an exception (#587)
* Add a test for the (<x> In @0) case that isn't working. * Change parser to not grab next token while parsing "in" unless it knows it was inside a parenthesis. This will fix it so that it doesn't eat the parenthesis for the surrounding statement when parsing an identifier.
1 parent 8933b95 commit 2252f95

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ Expression ParseIn()
340340
throw ParseError(op.Pos, Res.CloseParenOrCommaExpected);
341341
}
342342
}
343+
344+
// Since this started with an open paren, make sure to move off the close
345+
_textParser.NextToken();
343346
}
344347
else if (_textParser.CurrentToken.Id == TokenId.Identifier) // a single argument
345348
{
@@ -368,8 +371,6 @@ Expression ParseIn()
368371
{
369372
throw ParseError(op.Pos, Res.OpenParenOrIdentifierExpected);
370373
}
371-
372-
_textParser.NextToken();
373374
}
374375

375376
return accumulate;

test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ public void Parse_ParseMultipleInOperators()
139139
Check.That(parsedExpression).Equals("(((x.MainCompanyId == 1) OrElse (x.MainCompanyId == 2)) AndAlso ((x.Name == \"A\") OrElse (x.Name == \"B\")))");
140140
}
141141

142+
[Fact]
143+
public void Parse_ParseInWrappedInParenthesis()
144+
{
145+
// Arrange
146+
ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(typeof(Company), "x") };
147+
var sut = new ExpressionParser(parameters, "(MainCompanyId in @0)", new object[] { new long?[] { 1, 2 } }, null);
148+
149+
// Act
150+
var parsedExpression = sut.Parse(null).ToString();
151+
152+
// Assert
153+
Check.That(parsedExpression).Equals("value(System.Nullable`1[System.Int64][]).Contains(x.MainCompanyId)");
154+
}
155+
142156
[Theory]
143157
[InlineData("string(\"\")", "")]
144158
[InlineData("string(\"a\")", "a")]

0 commit comments

Comments
 (0)