Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LineFeed in string results in error on Evaluate #99

@magictucura

Description

@magictucura

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:)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions