1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 04:52:57 +08:00

Show error message on attempting to open a URL with an unsupported protocol

This commit is contained in:
Dean Herbert 2022-12-12 18:27:14 +09:00
parent cbd7cae70a
commit bf56f5f8c0
2 changed files with 21 additions and 0 deletions

View File

@ -26,6 +26,16 @@ namespace osu.Game.Tests.Chat
MessageFormatter.WebsiteRootUrl = originalWebsiteRootUrl; MessageFormatter.WebsiteRootUrl = originalWebsiteRootUrl;
} }
[Test]
public void TestUnsupportedProtocolLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a gopher://really-old-protocol we don't support." });
Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("gopher://really-old-protocol", result.Links[0].Url);
}
[Test] [Test]
public void TestBareLink() public void TestBareLink()
{ {

View File

@ -16,6 +16,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -406,6 +407,16 @@ namespace osu.Game
if (url.StartsWith('/')) if (url.StartsWith('/'))
url = $"{API.APIEndpointUrl}{url}"; url = $"{API.APIEndpointUrl}{url}";
if (!url.CheckIsValidUrl())
{
Notifications.Post(new SimpleErrorNotification
{
Text = $"The URL {url} has an unsupported or dangerous protocol and will not be opened.",
});
return;
}
externalLinkOpener.OpenUrlExternally(url, bypassExternalUrlWarning); externalLinkOpener.OpenUrlExternally(url, bypassExternalUrlWarning);
}); });