sll552/DiscordBee

validateDiscordID method will break on July 22, 2022

Closed this issue · 1 comments

Describe the bug

Plugin Version: v3.0.1

As of today (July 16, 2022), any new Discord ID will be be 18 digits in length (9xxxx....), a number that is a direct function of UNIX time. Similarly, the default Discord Application ID provided in MusicBeePlugin.Settings' defaults dictionary is also 18 digits long ("409394531948298250").

However, from 2022-07-22, 11:22:59 UTC onwards, any new Discord snowflakes (IDs) will be 19 digits long ("1000000000000000000"+).

This is a problem because the return value of MusicBeePlugin.UI.SettingsWindow's validateDiscordID() method is dependent on a length comparison between the application's "default" ID and the one provided by the user. This method will not return true if the length of the snowflake is not 18 digits long. As such, the IDs of any applications created after 2022-07-22, 11:22:59 UTC will not be accepted by the plugin.

Steps to Reproduce

Since this is not yet a problem, a unit test will be used to recreate the problem

  1. Create a unit test project to run the test in
  2. Copy the methods below into the unit test class (these are the same methods as the ones in MusicBeePlugin.UI.Settings, simply changed so that they can be run properly via the Unit Test environment).
bool validateDiscordId(string discordID)
{
    if (discordID.Length != Settings.defaults["DiscordAppId"].Length
        || discordID.Equals(Settings.defaults["DiscordAppId"])
        || !ContainsDigitsOnly(discordID))
    {
      return false;
    }
    return true;
}

private bool ContainsDigitsOnly(string s)
{
   foreach (char c in s)
   {
      if (c < '0' || c > '9')
      {
        return false;
      }
   }
   return true;
}
  1. Run the test, asserting that validateDiscordID("1000000000000000000") will be true.

Expected Behaviour

The test will be a success, returning true to a (what would be) valid Discord ID.

Actual Behaviour

Failure.

Possible (?) fix

Let validateDiscordID check the length of the string to be either 18 or 19 digits long, as 20-digit long snowflakes will only starting existing after circa 2090.

Screenshot

image

image

wow I thought they wouldnt use snowflakes for app ids but hey there we are. Nice catch btw.