Skip to content

Function expression failed with string paramater which contains \  #41

@lemanhtien

Description

@lemanhtien

Here is the default test case, which the result is correct

func testCallAnyExpressionSymbolEvaluatorConstant() {
        let expression = AnyExpression("foo('foo', 'bar')", constants: [
            "foo": { ($0[0] as! String) + ($0[1] as! String) } as AnyExpression.SymbolEvaluator,
        ])
        XCTAssertEqual(try expression.evaluate(), "foobar")
        XCTAssertEqual(expression.symbols, [.function("foo", arity: 2)])
    }

Modify the parameter value a bit, by adding "\", then the result is wrong

  func testCallAnyExpressionSymbolEvaluatorConstant() {
        let expression = AnyExpression("foo('foo\\s', 'bar')", constants: [
            "foo": { ($0[0] as! String) + ($0[1] as! String) } as AnyExpression.SymbolEvaluator,
        ])
        XCTAssertEqual(try expression.evaluate(), "foo\\sbar")
        XCTAssertEqual(expression.symbols, [.function("foo", arity: 2)])
    }

I tested several test case, and noticed that if the parameter is string, and it contains \\, the result will be wrong.

Do you have any ideas to update this one? I think it relates to the function parseEscapedIdentifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions