From b92cc6fb15bd1c4872457648170e03cb4dfbd47c Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 31 Mar 2015 23:52:27 +0200 Subject: [PATCH] Fixed: No longer possible to add protocol to a Host field (that's what Url fields are for) --- .../Download/Clients/Deluge/DelugeSettings.cs | 2 +- .../Download/Clients/Nzbget/NzbgetSettings.cs | 2 +- .../Download/Clients/Sabnzbd/SabnzbdSettings.cs | 2 +- .../Clients/Transmission/TransmissionSettings.cs | 2 +- .../Download/Clients/uTorrent/UTorrentSettings.cs | 2 +- src/NzbDrone.Core/Notifications/Growl/GrowlSettings.cs | 2 +- .../Notifications/MediaBrowser/MediaBrowserSettings.cs | 2 +- .../Notifications/Plex/PlexClientSettings.cs | 2 +- .../Notifications/Plex/PlexServerSettings.cs | 2 +- src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs | 2 +- src/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs | 2 +- src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs | 10 ++++++++-- 12 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs index c7cb5b0a1..be5b39078 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge { public DelugeSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.TvCategory).Matches("^[-a-z]*$").WithMessage("Allowed characters a-z and -"); diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs index f9f108bb6..3f0f01e9a 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget { public NzbgetSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Username).NotEmpty().When(c => !String.IsNullOrWhiteSpace(c.Password)); RuleFor(c => c.Password).NotEmpty().When(c => !String.IsNullOrWhiteSpace(c.Username)); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs index 0a8e556f6..7007f7d3a 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { public SabnzbdSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.ApiKey).NotEmpty() diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs index 3989aa790..19d9dcc1b 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission { public TransmissionSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.TvCategory).Matches(@"^\.?[-a-z]*$").WithMessage("Allowed characters a-z and -"); diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs index 4647a5076..bd3f813b7 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent { public UTorrentSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).InclusiveBetween(0, 65535); RuleFor(c => c.TvCategory).NotEmpty(); } diff --git a/src/NzbDrone.Core/Notifications/Growl/GrowlSettings.cs b/src/NzbDrone.Core/Notifications/Growl/GrowlSettings.cs index 04d864e96..a9a80f766 100644 --- a/src/NzbDrone.Core/Notifications/Growl/GrowlSettings.cs +++ b/src/NzbDrone.Core/Notifications/Growl/GrowlSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Growl { public GrowlSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); } } diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs index 71a5528e0..f89655aff 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Notifications.MediaBrowser { public MediaBrowserSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.ApiKey).NotEmpty(); } } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexClientSettings.cs b/src/NzbDrone.Core/Notifications/Plex/PlexClientSettings.cs index e1841ce6b..a36f08152 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexClientSettings.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexClientSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Plex { public PlexClientSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); } } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs index cc69e8a90..bb7977273 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerSettings.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Plex { public PlexServerSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).GreaterThan(0); } } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 6175c7031..bd340ef7d 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -113,7 +113,7 @@ namespace NzbDrone.Core.Notifications.Xbmc if (version == new XbmcVersion(0)) { - throw new InvalidXbmcVersionException("Verion received from XBMC is invalid, please correct your settings."); + throw new InvalidXbmcVersionException("Version received from XBMC is invalid, please correct your settings."); } Notify(settings, "Test Notification", "Success! XBMC has been successfully configured!"); diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs index cab9527e7..e1507d9bb 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Notifications.Xbmc { public XbmcSettingsValidator() { - RuleFor(c => c.Host).NotEmpty(); + RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.DisplayTime).GreaterThanOrEqualTo(2); } } diff --git a/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs b/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs index 2553b8964..ade8f810b 100644 --- a/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs +++ b/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs @@ -19,13 +19,19 @@ namespace NzbDrone.Core.Validation public static IRuleBuilderOptions HaveHttpProtocol(this IRuleBuilder ruleBuilder) { - return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(s)?://", RegexOptions.IgnoreCase)).WithMessage("must start with http:// or https://"); + return ruleBuilder.SetValidator(new RegularExpressionValidator("^https?://", RegexOptions.IgnoreCase)).WithMessage("must start with http:// or https://"); + } + + public static IRuleBuilderOptions ValidHost(this IRuleBuilder ruleBuilder) + { + ruleBuilder.SetValidator(new NotEmptyValidator(null)); + return ruleBuilder.SetValidator(new RegularExpressionValidator("^[-a-z0-9.]+$", RegexOptions.IgnoreCase)).WithMessage("must be valid Host without http://"); } public static IRuleBuilderOptions ValidRootUrl(this IRuleBuilder ruleBuilder) { ruleBuilder.SetValidator(new NotEmptyValidator(null)); - return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(?:s)?://[a-z0-9-.]+", RegexOptions.IgnoreCase)).WithMessage("must be valid URL that"); + return ruleBuilder.SetValidator(new RegularExpressionValidator("^https?://[-a-z0-9.]+", RegexOptions.IgnoreCase)).WithMessage("must be valid URL that starts with http(s)://"); } public static IRuleBuilderOptions ValidPort(this IRuleBuilder ruleBuilder)