The bug
Should DNS names be validated to be correct, then remove incorrect characters? Or at least strip whitespace on either side?
How to reproduce
Connect to " x.nerd.nu", you'll get an error about the server not being found.
Potential fix
Easy way to fix in java:
String servername; //assuming we're storing the info from the "Server Address" box into a string
servername = servername.trim();
Comments 14
Its not truly a bug, but could easily be rectified by removing all spaces from the server name string before attempting to connect. Removing the spaces should have no adverse affects as a server name can't have a space in it anyway.
Remember, bug fixes aren't always the result of bugs, sometimes they are just idiot proofing.
In any case just trim the String. It's very easy to get a surplus whitespace in when copying an address out of a web browser.
Further checking can be very tricky due to IDNA.
Confirmed in 14w08a. You may also mention that you are able to add a server to the server list with address " " and nothing more.
Confirmed for 1.10.2. " localhost" results in "cannot resolve hostname" instead of "can't connect to server".
For me it says "Unknown host", which is correct, because there's no server named " localhost". Where is the bug?
Can confirm for MC 1.12.1.
@unknown, when you type in " google.com" in the URL bar of your web browser, your browser won't tell you that the URL is invalid because it omits trailing and leading whitespaces by default. It does that because there are people out there in the vastness of the internet who are very good at making typos. Since whitespaces are invisible, those people probably wouldn't notice it when there was a whitespace at the beginning or at the end of the URL they just typed in and would very likely complain why they can't reach that URL. The same goes for Minecraft servers.
@unknown's quote is very fitting here.
Make something idiot proof and nature will create a better idiot.
Confirmed:
Perhaps some whitespace stripping and some regular expressions to validate the entry as valid IP/hostname: