Sanitise name input to prevent incorrect behaviour
Opened this issue · 13 comments
I can't seem to reproduce the bug. In any case, sanitisation of input should be implemented. If you are willing to, a PR is most welcome for its implementation. If and when I get time, I'll fix the issue. Thanks for bringing it to notice.
Ah yes, I can reproduce it now. Seems like a trivial fix, thank you
Hey!!
Anyone working on this issue? I would like to do something with this repo because
- It is CPP and I just finished learning the language
- It is a game
Go ahead! As far as I know, there are no takers yet :)
Sweet!!
Hey!
So I finally got around to working on this. Sorry about the delay.
What is the solution you are thinking about here? I don't want to try and implement something you don't think is needed
Hey, no worries! A PR was made (#44) that addressed this issue, though it cannot be merged right now due to conflicts. You can view it and make suggestions, or if you believe you have a better, more efficient solution, create a separate PR!
The solution I had in mind was a simple check to see whether the characters the person enters are alphanumeric only.
The effect is because of the way data is read from the input. It is using common console reading. But, in my opinion, you should consider using something with a better approach: reading directly from the terminal, using ncurses for *nix systems and console.h for Windows systems. Also, I could notice that CTRL C breaks the app. It should consider using signal handling to make the app close in a controller manner instead of relying on the default signal handler which kills the application.
@ronflima wouldn't using ncurses
be a slight overkill? Moreover, this would increase the requirement of separation of code for *nix systems and Windows.
It depends on your objectives. If you want to keep the code 100% portable, you must rely on STDC++ library and that’s it. However you will have a lot of usability issues since OS interface offered by STDC++ is really high level due to its generality.
Makes sense, though I haven't discarded the idea of using ncurses and console.h – just lacking a Windows environment to work and test on 😅. Could you elaborate on the usability issues?
system("clear"); works only on *nix systems, for instance. On Windows, you have to use something from the old conio.h or from console.h (I'm kind of outdated on this matter), or rely on Cygwin or other POSIX layer.
If the user presses CTRL-C, the game simply dies. If you press CTRL-J, which is an invalid keystroke, it will be echoed back to the terminal. You could be using a better menu based on up and down arrow keys instead to have the user to enter letters representing the menu items.
But, again, it all depends on your objectives. As much you control the console, more system dependent code is needed. The way to do so is to mimic STDC library: create general interfaces, letting the implementation to be compiled according to the host operating system.
Using ncurses
to improve user interactions too, just press a single key without enter.