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

A string from the standard input is incorrectly compared with another #80136

Closed
comminux opened this issue Aug 1, 2023 · 7 comments · Fixed by #99542
Closed

A string from the standard input is incorrectly compared with another #80136

comminux opened this issue Aug 1, 2023 · 7 comments · Fixed by #99542
Assignees
Milestone

Comments

@comminux
Copy link

comminux commented Aug 1, 2023

Godot version

v4.1.1.rc.custom_build.e709ad4d6

System information

Arch Linux x86_64

Issue description

The following condition will never be true, even if the user enters the value of another string correctly.

func _process(delta):
	print(OS.read_string_from_stdin() == "test")

Steps to reproduce

  1. Export the minimal reproduction project in zip or pack file.
  2. "godot --main-pack stdin-exported.zip"
  3. Enter the word "test" into the console and press enter.

Minimal reproduction project

stdin-mrp.zip

@AThousandShips
Copy link
Member

Have you tried if it matches "test\n"?

@comminux
Copy link
Author

comminux commented Aug 1, 2023

"test\n" is also not true

@AThousandShips
Copy link
Member

AThousandShips commented Aug 1, 2023

Can confirm that it does include a linebreak, and the actual line is "test\r\n", at least on Windows, you need to strip the newlines

Would need to be documented or discussed, exactly how it works

@comminux
Copy link
Author

comminux commented Aug 8, 2023

I read the description of the pull request for this method and figured out my problem. You need to use OS.read_string_from_stdin().strip_edges() and then string comparison will be correct.

I think it will be enough to leave a mention in the documentation for the strip_edges method for OS.read_string_from_stdin()

@AThousandShips
Copy link
Member

As I was saying, you didn't need to figure it out yourself 🙃

@comminux
Copy link
Author

After Godot 4.4 dev 5 stdin handling will work via OS.read_string_from_stdin(1024).strip_edges()

@akien-mga
Copy link
Member

In the end we assessed that it's a bug, and #99542 will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment