From a7fcfd5f0d19efcc8b6dda30749dac50563a0500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 10 Oct 2024 13:54:32 +0200 Subject: [PATCH] Fix discord RPC complaining yet again if given a single space character as activity state / details Closes https://github.com/ppy/osu/issues/30178. Really, discord? --- osu.Desktop/DiscordRichPresence.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 780d367900..5a7a01df1b 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -279,10 +279,12 @@ private static string clampLength(string str) // As above, discord decides that *non-empty* strings shorter than 2 characters cannot possibly be valid input, because... reasons? // And yes, that is two *characters*, or *codepoints*, not *bytes* as further down below (as determined by empirical testing). - // That seems very questionable, and isn't even documented anywhere. So to *make it* accept such valid input, - // just tack on enough of U+200B ZERO WIDTH SPACEs at the end. - if (str.Length < 2) - return str.PadRight(2, '\u200B'); + // Also, spaces don't count. Because reasons, clearly. + // That all seems very questionable, and isn't even documented anywhere. So to *make it* accept such valid input, + // just tack on enough of U+200B ZERO WIDTH SPACEs at the end. After making sure to trim whitespace. + string trimmed = str.Trim(); + if (trimmed.Length < 2) + return trimmed.PadRight(2, '\u200B'); if (Encoding.UTF8.GetByteCount(str) <= 128) return str;