Skip to content
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ install:

environment:
PATH: $(PATH);$(PROGRAMFILES)\dotnet\

# https://www.appveyor.com/docs/build-configuration/#secure-variables
# However, secure variables are not decoded during Pull Request builds which prevents someone from submitting PR with malicious build script displaying those variables. In more controlled environment through with a trusted team and private GitHub repositories there is an option on General tab of project settings to allow secure variables for PRs.
COVERALLS_REPO_TOKEN:
secure: tsTABRbCmdWFLT194XNIrpurerOfjN6cEoxt2RaSUfLmUIgra/+CwuqVkv0sPRop
SONAR_TOKEN:
secure: guog1+ttdnlD8sVgvizlewksm3qbO7dy2oZUcR8WhurWYvdOByinxXo732hmSaMT


before_build:
# Remove UAP10 and netstandard20 from csproj
#- cmd: copy /Y src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.AppVeyor.csproj src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj
Expand All @@ -39,7 +43,7 @@ before_build:

build_script:
# Begin SonarScanner
- dotnet sonarscanner begin /k:"system.linq.dynamic.core" /d:sonar.organization="stefh-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="%SONAR_TOKEN%" /v:"%APPVEYOR_BUILD_NUMBER%" /d:sonar.cs.opencover.reportsPaths="%CD%\coverage.xml"
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & "dotnet sonarscanner begin /k:\"system.linq.dynamic.core\" /d:sonar.organization=\"stefh-github\" /d:sonar.host.url=\"https://sonarcloud.io\" /d:sonar.login=\"%SONAR_TOKEN%\" /v:\"%APPVEYOR_BUILD_NUMBER%\" /d:sonar.cs.opencover.reportsPaths=\"%CD%\coverage.xml\"" }

# Build Code
- dotnet build src\EntityFramework.DynamicLinq\EntityFramework.DynamicLinq.csproj -c %CONFIGURATION%
Expand All @@ -59,7 +63,7 @@ test_script:
- cmd: '"OpenCover\tools\OpenCover.Console.exe" -target:dotnet.exe -targetargs:"test test\System.Linq.Dynamic.Core.Tests\System.Linq.Dynamic.Core.Tests.csproj --configuration %CONFIGURATION% --framework netcoreapp1.1 --no-build" -output:coverage.xml -register:user -filter:"+[Microsoft.EntityFrameworkCore.DynamicLinq]* +[System.Linq.Dynamic.Core]* -[*Tests*]*" -nodefaultfilters -returntargetcode -oldstyle'
- codecov -f "coverage.xml"
- coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml
- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & "dotnet sonarscanner end /d:sonar.login=\"%SONAR_TOKEN%\"" }

# Run tests for EntityFramework.DynamicLinq
- dotnet test -c %CONFIGURATION% --no-build test\EntityFramework.DynamicLinq.Tests\EntityFramework.DynamicLinq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\TestEnum.cs">
<Link>Helpers\TestEnum.cs</Link>
</Compile>
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserProfileDetails.cs">
<Link>Helpers\Models\UserProfileDetails.cs</Link>
</Compile>
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserState.cs">
<Link>Helpers\Models\UserState.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static LambdaExpression ParseLambda([NotNull] Type itType, [CanBeNull] Ty
[PublicAPI]
public static LambdaExpression ParseLambda([CanBeNull] ParsingConfig parsingConfig, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values)
{
return ParseLambda(true, itType, resultType, expression, parsingConfig, values);
return ParseLambda(parsingConfig, true, itType, resultType, expression, values);
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ Expression ParseStringLiteral()
_textParser.ValidateToken(TokenId.StringLiteral);
char quote = _textParser.CurrentToken.Text[0];
string s = _textParser.CurrentToken.Text.Substring(1, _textParser.CurrentToken.Text.Length - 2);
int index1 = 0;
while (true)
{
int index2 = s.IndexOf(quote, index1);
if (index2 < 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use {} in this new code. Example:

if (index2 < 0)
{
    break;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! I'm done.

break;
if (index2 + 1 < s.Length && s[index2 + 1] == quote)
s = s.Remove(index2, 1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use {} in this new code. Example:

if (index2 < 0)
{
    break;
}

Copy link
Copy Markdown
Contributor Author

@OlegNadymov OlegNadymov Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefH Ok! It was done.

index1 = index2 + 1;
}

if (quote == '\'')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class ComplexParseLambda3Result
public int TotalIncome { get; set; }
}

public class CustomClassWithStaticMethod
{
public static int GetAge(int x) => x;
}

private class TestCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
{
private HashSet<Type> _customTypes;
Expand All @@ -44,6 +49,7 @@ public virtual HashSet<Type> GetCustomTypes()
}

_customTypes = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { GetType().GetTypeInfo().Assembly }));
_customTypes.Add(typeof(CustomClassWithStaticMethod));
return _customTypes;
}
}
Expand Down Expand Up @@ -413,5 +419,38 @@ public void ParseLambda_IllegalMethodCall_ThrowsException()
})
.Throws<ParseException>().WithMessage("Methods on type 'Stream' are not accessible");
}

[Fact]
public void ParseLambda_CustomMethod()
{
// Assign
var config = new ParsingConfig
{
CustomTypeProvider = new TestCustomTypeProvider()
};

var context = new CustomClassWithStaticMethod();
string expression = $"{nameof(CustomClassWithStaticMethod)}.{nameof(CustomClassWithStaticMethod.GetAge)}(10)";

// Act
var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(CustomClassWithStaticMethod), null, expression);
Delegate del = lambdaExpression.Compile();
int result = (int)del.DynamicInvoke(context);

// Assert
Check.That(result).IsEqualTo(10);
}

[Fact]
public void ParseLambda_With_InnerStringLiteral()
{
var originalTrueValue = "simple + \"quoted\"";
var doubleQuotedTrueValue = "simple + \"\"quoted\"\"";
var expressionText = $"iif(1>0, \"{doubleQuotedTrueValue}\", \"false\")";
var lambda = DynamicExpressionParser.ParseLambda(typeof(string), null, expressionText);
var del = lambda.Compile();
object result = del.DynamicInvoke(String.Empty);
Check.That(result).IsEqualTo(originalTrueValue);
}
}
}