godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.43k stars 21.27k forks source link

Triple quoted strings cannot be compared to typical strings with the Expression class #98481

Open justinbangerter opened 1 month ago

justinbangerter commented 1 month ago

Tested versions

System information

Godot v4.3.stable unknown - Artix Linux

Issue description

In the editor, if you compare a double quoted string to a triple double quoted string, they are equivalent.

If you use the Expression class to compare them, they are not equivalent.

I'm guessing it shouldn't matter whether it's a double, single, triple double or triple single quoted string. They should all be the same if the contents mean the same thing.

Steps to reproduce

  func evaluate():
      if "x" == """x""":
          print("sane")
      else:
          print("insane")

      var xp = Expression.new()
      var err = xp.parse('"x" == """x"""', [])
      if err != OK:
          push_error("failed to parse")
      var res = xp.execute([])
      if xp.has_execute_failed():
          push_error(xp.get_error_text())
      print('Does expression.execute() think they are the same?')
      print(res)

Prints:

sane
Does expression.execute() think they are the same?
false

Should print:

sane
Does expression.execute() think they are the same?
true

For any combination of quote types.

Minimal reproduction project (MRP)

godot-quote-bug.zip

dalexeev commented 1 month ago

It looks like Expression doesn't support triple quoted strings, but it doesn't report a parse error.

var e := Expression.new()
print(error_string(e.parse('"""test"""'))) # OK
print(var_to_str(e.execute())) # ""
print(error_string(e.parse('"a""test"""'))) # OK
print(var_to_str(e.execute())) # "a"