1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00

Fixed use of duplicate variable as a source in FOR IN statement (#196)

This commit is contained in:
Tim Voronov 2018-11-30 13:12:00 -05:00 committed by GitHub
parent dc3de71554
commit b3611c5713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -197,4 +197,15 @@ func TestLet(t *testing.T) {
So(err, ShouldBeNil)
So(string(out), ShouldEqual, "[1,2,3]")
})
Convey("Should not compile FOR foo IN foo", t, func() {
c := compiler.New()
_, err := c.Compile(`
FOR foo IN foo
RETURN foo
`)
So(err, ShouldNotBeNil)
})
}

View File

@ -160,17 +160,7 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco
var keyVarName string
parsedClauses := make([]forOption, 0, 10)
valVar := ctx.ForExpressionValueVariable()
valVarName = valVar.GetText()
forInScope := scope.Fork()
forInScope.SetVariable(valVarName)
keyVar := ctx.ForExpressionKeyVariable()
if keyVar != nil {
keyVarName = keyVar.GetText()
forInScope.SetVariable(keyVarName)
}
srcCtx := ctx.ForExpressionSource().(*fql.ForExpressionSourceContext)
srcExp, err := v.doVisitForExpressionSource(srcCtx, forInScope)
@ -179,6 +169,23 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco
return nil, err
}
valVar := ctx.ForExpressionValueVariable()
valVarName = valVar.GetText()
if err := forInScope.SetVariable(valVarName); err != nil {
return nil, err
}
keyVar := ctx.ForExpressionKeyVariable()
if keyVar != nil {
keyVarName = keyVar.GetText()
if err := forInScope.SetVariable(keyVarName); err != nil {
return nil, err
}
}
src, err := expressions.NewDataSource(
v.getSourceMap(srcCtx),
valVarName,