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

Sanitise name input to prevent incorrect behaviour #22

Open
straymonk opened this issue Sep 20, 2018 · 13 comments
Open

Sanitise name input to prevent incorrect behaviour #22

straymonk opened this issue Sep 20, 2018 · 13 comments
Labels
bug Something isn't working hard-blocked Another issue is preventing this moving forward. It cannot continue without clearing the issue.

Comments

@straymonk
Copy link

straymonk commented Sep 20, 2018

test

The highscore page goes into the endless cycle and prints new lines.

upd:
Name length issue. Can be reproduced by entering name with size >18.

@plibither8
Copy link
Owner

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.

@plibither8
Copy link
Owner

Ah yes, I can reproduce it now. Seems like a trivial fix, thank you

@plibither8 plibither8 added bug Something isn't working good first issue Good for newcomers hacktoberfest labels Sep 28, 2018
@plibither8 plibither8 changed the title The highscore page breaks if you enter a name consisting of the symbols produced by the arrows Sanitise name input to prevent incorrect behaviour Sep 28, 2018
@mayurdw
Copy link

mayurdw commented Oct 1, 2018

Hey!!
Anyone working on this issue? I would like to do something with this repo because

  1. It is CPP and I just finished learning the language
  2. It is a game

@plibither8
Copy link
Owner

Go ahead! As far as I know, there are no takers yet :)

@mayurdw
Copy link

mayurdw commented Oct 3, 2018

Sweet!!

@mayurdw
Copy link

mayurdw commented Oct 8, 2018

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

@plibither8
Copy link
Owner

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.

@ronflima
Copy link

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.

@plibither8
Copy link
Owner

@ronflima wouldn't using ncurses be a slight overkill? Moreover, this would increase the requirement of separation of code for *nix systems and Windows.

@ronflima
Copy link

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.

@plibither8
Copy link
Owner

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?

@ronflima
Copy link

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.

@tiendq
Copy link
Contributor

tiendq commented Oct 26, 2018

Using ncurses to improve user interactions too, just press a single key without enter.

@tcoyvwac tcoyvwac added hard-blocked Another issue is preventing this moving forward. It cannot continue without clearing the issue. and removed good first issue Good for newcomers labels Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hard-blocked Another issue is preventing this moving forward. It cannot continue without clearing the issue.
Projects
None yet
Development

No branches or pull requests

6 participants