From 9253058a73ba1d06c14b9b99e4bc6a96db319d13 Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 15 Apr 2020 19:06:09 +1200 Subject: [PATCH] node: add bailout cases for eval() and extract() --- node.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index 1492d89..c49d2bf 100644 --- a/node.go +++ b/node.go @@ -14,6 +14,8 @@ import ( "github.com/z7zmey/php-parser/node/name" "github.com/z7zmey/php-parser/node/scalar" "github.com/z7zmey/php-parser/node/stmt" + + "php2go/parseutil" ) func nodeTypeString(n node.Node) string { @@ -1192,6 +1194,10 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error) callParams = append(callParams, `-1`) // replaceAll // There is a strings.ReplaceAll() added in go1.12 (2018), which is still pretty recent i.e. not in Debian Stable (buster) } + + } else if funcName == `extract` { + return "", parseErr{n, fmt.Errorf("Unsupported dynamic function `\\extract()`")} + } return funcName + "(" + strings.Join(callParams, ", ") + ")", nil // expr only, no semicolon/newline @@ -1320,6 +1326,9 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error) return "os.Exit(" + child + ")", nil } + case *expr.Eval: + return "", parseErr{n, fmt.Errorf("Unsupported use of eval()")} + case *expr.PreInc: // """In Go, i++ is a statement, not an expression. So you can't use its value in another expression such as a function call.""" v, err := this.convert(n.Variable) @@ -2105,7 +2114,7 @@ func (this *conversionState) convertFunctionCommon(params []node.Node, returnTyp // any assignment expressions func hasInteriorAssignment(n node.Node) (hasAnyAssign bool, err error) { - err = walk(n, func(n node.Node) error { + err = parseutil.SimpleWalk(n, func(n node.Node) error { if _, ok := n.(*assign.Assign); ok { hasAnyAssign = true }