Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression parsing/executing invalid notation #81895

Open
oganm opened this issue Sep 19, 2023 · 1 comment · May be fixed by #84299 or #97754
Open

Expression parsing/executing invalid notation #81895

oganm opened this issue Sep 19, 2023 · 1 comment · May be fixed by #84299 or #97754

Comments

@oganm
Copy link
Contributor

oganm commented Sep 19, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Godot v4.1.1.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated GeForce RTX 2060 () - Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 Threads)

Issue description

Currently, an expression such as "4random_characters" that I think should be invalid can be happily parsed and executed, resolving into a 4. My initial understanding of how expressions were supposed to work would have lead me to believe this would have returned an error since usually trying to operate on 4random_characters within a script would result in an invalid notation error. Either the documentation isn't clear enough on what is happening behind the scenes or this can be considered an unintentional behaviour.

Steps to reproduce

Via an editor script

@tool
extends EditorScript

func _run():
	var expr = Expression.new()
	print(expr.parse('4random_characters'))
	print(expr.execute())

Parsing will return a 0 after successful operation
The execution will return a 4.

Minimal reproduction project

Trivial via an editor script

@tokomine
Copy link

The logic related to this bug seems to be in line 414 of expression.cpp. I guess we can add a check here, and return ERR_PARSE_ERROR if c is not a whitespace character.

						if (reading == READING_DONE) {
							break;
						}
						num += String::chr(c);
						c = GET_CHAR();
						is_first_char = false;
					}

					str_ofs--;

					r_token.type = TK_CONSTANT;

					if (is_float) {
						r_token.value = num.to_float();
					} else if (bin_beg) {
						r_token.value = num.bin_to_int();
					} else if (hex_beg) {
						r_token.value = num.hex_to_int();
					} else {
						r_token.value = num.to_int();
					}
					return OK;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants