Trim trailing slashes from server URL.

This commit is contained in:
Jared Goodwin 2021-04-15 18:39:55 -07:00
parent b6f0df54a7
commit 50237c8167
4 changed files with 23 additions and 25 deletions

View File

@ -69,7 +69,7 @@ namespace Remotely.Desktop.Core.Services
catch { }
}
Connection = new HubConnectionBuilder()
.WithUrl($"{host}/CasterHub")
.WithUrl($"{host.Trim().TrimEnd('/')}/CasterHub")
.AddMessagePackProtocol()
.WithAutomaticReconnect()
.Build();

View File

@ -214,24 +214,20 @@ namespace Remotely.Desktop.Linux.ViewModels
}
await prompt.ShowDialog(MainWindow.Current);
var result = prompt.ViewModel.Host?.Trim();
var result = prompt.ViewModel.Host?.Trim()?.TrimEnd('/');
if (result is null)
if (!Uri.TryCreate(result, UriKind.Absolute, out var serverUri) ||
(serverUri.Scheme != Uri.UriSchemeHttp && serverUri.Scheme != Uri.UriSchemeHttps))
{
Logger.Write("Server URL is not valid.");
await MessageBox.Show("Server URL must be a valid Uri (e.g. https://app.remotely.one).", "Invalid Server URL", MessageBoxType.OK);
return;
}
if (!result.StartsWith("https://") && !result.StartsWith("http://"))
{
result = $"https://{result}";
}
if (result != Host)
{
Host = result;
var config = _configService.GetConfig();
config.Host = Host;
_configService.Save(config);
}
Host = result;
var config = _configService.GetConfig();
config.Host = Host;
_configService.Save(config);
}

View File

@ -257,18 +257,20 @@ namespace Remotely.Desktop.Win.ViewModels
prompt.Owner = App.Current?.MainWindow;
prompt.ShowDialog();
var result = prompt.ViewModel.Host?.Trim();
if (!result.StartsWith("https://") && !result.StartsWith("http://"))
var result = prompt.ViewModel.Host?.Trim()?.TrimEnd('/');
if (!Uri.TryCreate(result, UriKind.Absolute, out var serverUri) ||
(serverUri.Scheme != Uri.UriSchemeHttp && serverUri.Scheme != Uri.UriSchemeHttps))
{
result = $"https://{result}";
}
if (result != Host)
{
Host = result;
var config = _configService.GetConfig();
config.Host = Host;
_configService.Save(config);
Logger.Write("Server URL is not valid.");
MessageBox.Show("Server URL must be a valid Uri (e.g. https://app.remotely.one).", "Invalid Server URL", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Host = result;
var config = _configService.GetConfig();
config.Host = Host;
_configService.Save(config);
}
public void ShutdownApp()

View File

@ -12,7 +12,7 @@ namespace Remotely.Shared.Models
public string Host
{
get => _host;
get => _host.TrimEnd('/');
set
{
_host = value?.TrimEnd('/');