Trim called without arguments throws index out of range (#77)

* Check arguments before accessing in jet string method translator

* Change expected result on to lower and to upper query tests

* Change expected result on trim query tests

* Remove original fix and fix condition chaining in trim clause generation

Co-authored-by: Floris Verhoeven <florisverhoeven@outlook.com>
pull/79/head
Floris Verhoeven 5 years ago committed by GitHub
parent 2b44bac7ba
commit 23b8257fc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -110,8 +110,8 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
// Jet TRIM does not take arguments.
// _trimWithNoParam is only available since .NET Core 2.0 (or .NET Standard 2.1).
if (Equals(method, _trimWithNoParam) ||
Equals(method, _trimWithChars) &&
(arguments[0] as SqlConstantExpression)?.Value == null || ((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0)
Equals(method, _trimWithChars) && ((arguments[0] as SqlConstantExpression)?.Value == null ||
((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0))
{
return _sqlExpressionFactory.Function("TRIM", new[] {instance}, method.ReturnType);
}
@ -119,8 +119,8 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
// Jet LTRIM does not take arguments
// _trimStartWithNoParam is only available since .NET Core 2.0 (or .NET Standard 2.1).
if (Equals(method, _trimStartWithNoParam) ||
Equals(method, _trimStartWithChars) &&
(arguments[0] as SqlConstantExpression)?.Value == null || ((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0)
Equals(method, _trimStartWithChars) && ((arguments[0] as SqlConstantExpression)?.Value == null ||
((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0))
{
return _sqlExpressionFactory.Function("LTRIM", new[] {instance}, method.ReturnType);
}
@ -128,8 +128,8 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
// Jet RTRIM does not take arguments
// _trimEndWithNoParam is only available since .NET Core 2.0 (or .NET Standard 2.1).
if (Equals(method, _trimEndWithNoParam) ||
Equals(method, _trimEndWithChars) &&
(arguments[0] as SqlConstantExpression)?.Value == null || ((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0)
Equals(method, _trimEndWithChars) && ((arguments[0] as SqlConstantExpression)?.Value == null ||
((arguments[0] as SqlConstantExpression)?.Value as Array)?.Length == 0))
{
return _sqlExpressionFactory.Function("RTRIM", new[] {instance}, method.ReturnType);
}

@ -847,7 +847,7 @@ WHERE (NEWID() <> '00000000-0000-0000-0000-000000000000') OR NEWID() IS NULL");
AssertSql(
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
FROM `Customers` AS `c`
WHERE UPPER(`c`.`CustomerID`) = 'ALFKI'");
WHERE UCASE(`c`.`CustomerID`) = 'ALFKI'");
}
public override async Task Where_string_to_lower(bool isAsync)
@ -857,7 +857,7 @@ WHERE UPPER(`c`.`CustomerID`) = 'ALFKI'");
AssertSql(
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
FROM `Customers` AS `c`
WHERE LOWER(`c`.`CustomerID`) = 'alfki'");
WHERE LCASE(`c`.`CustomerID`) = 'alfki'");
}
public override async Task Where_functions_nested(bool isAsync)
@ -1413,7 +1413,7 @@ WHERE RTRIM(`c`.`ContactTitle`) = 'Owner'");
AssertSql(
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
FROM `Customers` AS `c`
WHERE LTRIM(RTRIM(`c`.`ContactTitle`)) = 'Owner'");
WHERE TRIM(`c`.`ContactTitle`) = 'Owner'");
}
[ConditionalTheory(Skip = "Issue#17328")]

Loading…
Cancel
Save