Skip to content

Commit 86b9cd8

Browse files
committed
Incorrect parse of the method argument when it starts with delimiter #57
1 parent 048a4e5 commit 86b9cd8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/NReco.LambdaParser.Tests/LambdaParserTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections;
3+
using System.Collections.Generic;
44
using System.Diagnostics;
55
using Xunit;
66

@@ -79,6 +79,13 @@ public void Eval() {
7979

8080
Assert.Equal(true, lambdaParser.Eval(" (1+testObj.IntProp)==2 ? testObj.FldTrue : false ", varContext));
8181

82+
Assert.Equal("3", lambdaParser.Eval("toString( (1+2) )", varContext) as string);
83+
Assert.Equal("3", lambdaParser.Eval("(1+2).ToString()", varContext) as string);
84+
85+
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("toString( (1+2)", varContext));
86+
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("toString( (1+2), )", varContext));
87+
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("toString( 1 ", varContext));
88+
8289
Assert.Equal("ab2_3", lambdaParser.Eval(" \"a\"+testObj.Format(\"b{0}_{1}\", 2, \"3\".ToString() ).ToString() ", varContext));
8390

8491
Assert.Equal(true, lambdaParser.Eval(" testObj.Hash[\"a\"] == \"1\"", varContext));
@@ -104,6 +111,9 @@ public void Eval() {
104111
Assert.Equal(3, lambdaParser.Eval(" new { {\"a\", 1}, {\"b\", 2}, {\"c\", 3} }.Count ", varContext));
105112
Assert.Equal(3, lambdaParser.Eval(" { \"a\": 1, \"b\": 2, \"c\": 3 }.Count ", varContext));
106113
Assert.Equal(0, lambdaParser.Eval(" { }.Count ", varContext));
114+
115+
Assert.Equal("1", lambdaParser.Eval("toString( { \"a\": 1 }.Count ) ", varContext) as string);
116+
107117
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("{ \"a\": 1, \"b\": 2, }", varContext));
108118
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("{ \"a\" }", varContext));
109119
Assert.Throws<LambdaParserException>(() => lambdaParser.Eval("{ \"a\": }", varContext));

src/NReco.LambdaParser/Linq/LambdaParser.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,20 @@ protected int ReadCallArguments(string expr, int start, string endLexem, List<Ex
610610
do {
611611
var lexem = ReadLexem(expr, end);
612612
if (lexem.Type == LexemType.Delimiter) {
613-
if (lexem.GetValue() == endLexem) {
614-
return lexem.End;
615-
} else if (lexem.GetValue() == ",") {
613+
if (lexem.GetValue()==endLexem)
614+
return lexem.End; // no more arguments
615+
616+
if (lexem.GetValue()==",") {
616617
if (args.Count == 0) {
617-
throw new LambdaParserException(expr, lexem.Start, "Value missed");
618+
throw new LambdaParserException(expr, lexem.Start, "Value expected before ','");
618619
}
619620
end = lexem.End;
620-
} else {
621-
throw new LambdaParserException(expr, lexem.Start, String.Format("Expected '{0}' or ','", endLexem));
622-
}
621+
}
623622
}
623+
if (lexem.Type==LexemType.Stop) {
624+
throw new LambdaParserException(expr, lexem.Start, String.Format("Expected '{0}' or ','", endLexem));
625+
}
626+
624627
// read parameter
625628
var paramExpr = ParseConditional(expr, end, vars);
626629
args.Add(ExprConvertToObjectIfNeeded(paramExpr.Expr));

0 commit comments

Comments
 (0)