Skip to content

Commit 870eb29

Browse files
OlegNadymovStefH
authored andcommitted
Fix the problem with inner double quotes (#195)
* Fix for ParseLambda with itType and resultType: correct order of arguments * Add references for missing classes * Fix for missing classes: UserState and UserProfileDetails * Small update on unit-test (no need to check for `DoesNotThrow`) * add comment to appveyor * Only run SonarScanner on master branch * APPVEYOR_REPO_BRANCH * APPVEYOR_PULL_REQUEST_NUMBER * No working unit test for inner double quotes * Fix for inner double quotes * Using {}
1 parent 22ef22c commit 870eb29

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ install:
2121
# 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.
2222
environment:
2323
PATH: $(PATH);$(PROGRAMFILES)\dotnet\
24+
25+
# https://www.appveyor.com/docs/build-configuration/#secure-variables
26+
# 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.
2427
COVERALLS_REPO_TOKEN:
2528
secure: tsTABRbCmdWFLT194XNIrpurerOfjN6cEoxt2RaSUfLmUIgra/+CwuqVkv0sPRop
2629
SONAR_TOKEN:
@@ -62,6 +65,7 @@ test_script:
6265
- 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'
6366
- codecov -f "coverage.xml"
6467
- coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml
68+
6569
- ps: 'if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & dotnet sonarscanner end /d:sonar.login="$env:SONAR_TOKEN" }'
6670

6771
# Run tests for EntityFramework.DynamicLinq

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

+15
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,21 @@ Expression ParseStringLiteral()
755755
_textParser.ValidateToken(TokenId.StringLiteral);
756756
char quote = _textParser.CurrentToken.Text[0];
757757
string s = _textParser.CurrentToken.Text.Substring(1, _textParser.CurrentToken.Text.Length - 2);
758+
int index1 = 0;
759+
while (true)
760+
{
761+
int index2 = s.IndexOf(quote, index1);
762+
if (index2 < 0)
763+
{
764+
break;
765+
}
766+
767+
if (index2 + 1 < s.Length && s[index2 + 1] == quote)
768+
{
769+
s = s.Remove(index2, 1);
770+
}
771+
index1 = index2 + 1;
772+
}
758773

759774
if (quote == '\'')
760775
{

test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,17 @@ public void ParseLambda_CustomMethod()
440440
// Assert
441441
Check.That(result).IsEqualTo(10);
442442
}
443+
444+
[Fact]
445+
public void ParseLambda_With_InnerStringLiteral()
446+
{
447+
var originalTrueValue = "simple + \"quoted\"";
448+
var doubleQuotedTrueValue = "simple + \"\"quoted\"\"";
449+
var expressionText = $"iif(1>0, \"{doubleQuotedTrueValue}\", \"false\")";
450+
var lambda = DynamicExpressionParser.ParseLambda(typeof(string), null, expressionText);
451+
var del = lambda.Compile();
452+
object result = del.DynamicInvoke(String.Empty);
453+
Check.That(result).IsEqualTo(originalTrueValue);
454+
}
443455
}
444456
}

0 commit comments

Comments
 (0)