Merge pull request #11755 from peppy/fix-message-formatter-domain

Fix MessageFormatter not working for custom endpoints
This commit is contained in:
Dan Balasescu
2021-02-12 16:01:55 +09:00
committed by GitHub
3 changed files with 32 additions and 17 deletions

View File

@ -49,6 +49,18 @@ namespace osu.Game.Online.Chat
// Unicode emojis
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
/// <summary>
/// The root URL for the website, used for chat link matching.
/// </summary>
public static string WebsiteRootUrl
{
set => websiteRootUrl = value
.Trim('/') // trim potential trailing slash/
.Split('/').Last(); // only keep domain name, ignoring protocol.
}
private static string websiteRootUrl = "osu.ppy.sh";
private static void handleMatches(Regex regex, string display, string link, MessageFormatterResult result, int startIndex = 0, LinkAction? linkActionOverride = null, char[] escapeChars = null)
{
int captureOffset = 0;
@ -119,7 +131,7 @@ namespace osu.Game.Online.Chat
case "http":
case "https":
// length > 3 since all these links need another argument to work
if (args.Length > 3 && args[1] == "osu.ppy.sh")
if (args.Length > 3 && args[1].EndsWith(websiteRootUrl, StringComparison.OrdinalIgnoreCase))
{
var mainArg = args[3];