1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:13:21 +08:00

Merge pull request #11757 from peppy/fix-beatmap-links

Fix osu-web beatmap links not linking to specific beatmap
This commit is contained in:
Dan Balasescu 2021-02-12 16:01:41 +09:00 committed by GitHub
commit 352cc7e4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 8 deletions

View File

@ -21,6 +21,25 @@ namespace osu.Game.Tests.Chat
Assert.AreEqual(36, result.Links[0].Length);
}
[TestCase(LinkAction.OpenBeatmap, "456", "https://osu.ppy.sh/beatmapsets/123#osu/456")]
[TestCase(LinkAction.OpenBeatmap, "456", "https://osu.ppy.sh/beatmapsets/123#osu/456?whatever")]
[TestCase(LinkAction.OpenBeatmap, "456", "https://osu.ppy.sh/beatmapsets/123/456")]
[TestCase(LinkAction.External, null, "https://osu.ppy.sh/beatmapsets/abc/def")]
[TestCase(LinkAction.OpenBeatmapSet, "123", "https://osu.ppy.sh/beatmapsets/123")]
[TestCase(LinkAction.OpenBeatmapSet, "123", "https://osu.ppy.sh/beatmapsets/123/whatever")]
[TestCase(LinkAction.External, null, "https://osu.ppy.sh/beatmapsets/abc")]
public void TestBeatmapLinks(LinkAction expectedAction, string expectedArg, string link)
{
Message result = MessageFormatter.FormatMessage(new Message { Content = link });
Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual(expectedAction, result.Links[0].Action);
Assert.AreEqual(expectedArg, result.Links[0].Argument);
if (expectedAction == LinkAction.External)
Assert.AreEqual(link, result.Links[0].Url);
}
[Test]
public void TestMultipleComplexLinks()
{

View File

@ -121,20 +121,40 @@ namespace osu.Game.Online.Chat
// length > 3 since all these links need another argument to work
if (args.Length > 3 && args[1] == "osu.ppy.sh")
{
var mainArg = args[3];
switch (args[2])
{
// old site only
case "b":
case "beatmaps":
return new LinkDetails(LinkAction.OpenBeatmap, args[3]);
{
string trimmed = mainArg.Split('?').First();
if (int.TryParse(trimmed, out var id))
return new LinkDetails(LinkAction.OpenBeatmap, id.ToString());
break;
}
case "s":
case "beatmapsets":
case "d":
return new LinkDetails(LinkAction.OpenBeatmapSet, args[3]);
{
if (args.Length > 4 && int.TryParse(args[4], out var id))
// https://osu.ppy.sh/beatmapsets/1154158#osu/2768184
return new LinkDetails(LinkAction.OpenBeatmap, id.ToString());
// https://osu.ppy.sh/beatmapsets/1154158#whatever
string trimmed = mainArg.Split('#').First();
if (int.TryParse(trimmed, out id))
return new LinkDetails(LinkAction.OpenBeatmapSet, id.ToString());
break;
}
case "u":
case "users":
return new LinkDetails(LinkAction.OpenUserProfile, args[3]);
return new LinkDetails(LinkAction.OpenUserProfile, mainArg);
}
}
@ -183,10 +203,9 @@ namespace osu.Game.Online.Chat
case "osump":
return new LinkDetails(LinkAction.JoinMultiplayerMatch, args[1]);
default:
return new LinkDetails(LinkAction.External, null);
}
return new LinkDetails(LinkAction.External, null);
}
private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3)
@ -259,8 +278,9 @@ namespace osu.Game.Online.Chat
public class LinkDetails
{
public LinkAction Action;
public string Argument;
public readonly LinkAction Action;
public readonly string Argument;
public LinkDetails(LinkAction action, string argument)
{