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

Ip adress sanitization for MP Menu screen #196

Merged
merged 3 commits into from
Apr 19, 2021

Conversation

pGlase
Copy link

@pGlase pGlase commented Apr 19, 2021

After being annoyed by Copy&Paste errors when copying from Discord i figured I could add this as an entry exercise.
Maybe this is a good idea to prevent A) Crashes on invalid IPs and B) Give at least a little feedback about IPv4 only.

Please let me know if this is useable for the project, I am usually a C++ dev.

@pGlase pGlase changed the title Ip adress sanitize Ip adress sanitazion for MP Menu screen Apr 19, 2021
@pGlase pGlase changed the title Ip adress sanitazion for MP Menu screen Ip adress sanitization for MP Menu screen Apr 19, 2021
Copy link
Contributor

@Mushroom Mushroom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, as an embedded dev I understand your approach completely, but this is not the C# way :)

I have suggested a better alternative

@@ -171,6 +171,18 @@ private static void OnJoinGameButtonClick()
string ip = parts[0];
int port;

//remove copy and paste mistakes and update the textbox to prevent user confusion in case of invalid ip address
ip = SanitizeIpAddressString(ip);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using String.Trim() is probably better than a new function here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trim is identical to Trim(whitespace)

NebulaPatcher/Patches/Dynamic/UIMainMenu_Patch.cs Outdated Show resolved Hide resolved
NebulaPatcher/Patches/Dynamic/UIMainMenu_Patch.cs Outdated Show resolved Hide resolved
@pGlase pGlase requested a review from Mushroom April 19, 2021 20:11
@hubastard hubastard merged commit bfa53d6 into NebulaModTeam:master Apr 19, 2021
@@ -171,6 +171,18 @@ private static void OnJoinGameButtonClick()
string ip = parts[0];
int port;

//remove copy and paste mistakes and update the textbox to prevent user confusion in case of invalid ip address
ip = ip.Trim('\r', '\n', '\t', ' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all already considered whitespace by c#

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

Successfully merging this pull request may close these issues.

5 participants