PaesslerAG / gval

Expression evaluation in golang
BSD 3-Clause "New" or "Revised" License
713 stars 83 forks source link

LineFeed in string results in error on Evaluate #99

Open mjurczik opened 10 months ago

mjurczik commented 10 months ago

Hello,

if the expression contains a line feed character instead of the string representation parsing of expression fails. I don't know if this is intentional to only allow single line expressions and if it is my responsibility to replace all new line runes with their string representation.

Example code:

package main

import (
    "fmt"
    "github.com/PaesslerAG/gval"
)

func main() {
    expressionWithLF := `"hello
world"`
expressionWithNewLine := `"hello\nworld"`
eval(expressionWithLF)
eval(expressionWithNewLine)

}

func eval(expression string) {
    r, err := gval.Evaluate(expression, nil)
    fmt.Println(r, err)
    fmt.Println("---")
}

Output

<nil> parsing error: "hello
world"  :1:1 - 2:1 could not parse string: invalid syntax
---
hello
world <nil>
---

Take care:)