From 18971f9ea2e6e084745d1c82b456b2f501dcaad0 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 22 Jul 2017 22:14:06 +0200 Subject: [PATCH] Check for whitespace in IsValidUrl. closes #2020 --- .../ExtensionTests/UrlExtensionsFixture.cs | 29 +++++++++++++++++++ .../NzbDrone.Common.Test.csproj | 1 + .../Extensions/UrlExtensions.cs | 5 ++++ 3 files changed, 35 insertions(+) create mode 100644 src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs diff --git a/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs b/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs new file mode 100644 index 000000000..eae0736dc --- /dev/null +++ b/src/NzbDrone.Common.Test/ExtensionTests/UrlExtensionsFixture.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Extensions; + +namespace NzbDrone.Common.Test.ExtensionTests +{ + [TestFixture] + public class UrlExtensionsFixture + { + [TestCase("http://my.local/url")] + [TestCase("https://my.local/url")] + public void should_report_as_valid_url(string url) + { + url.IsValidUrl().Should().BeTrue(); + } + + [TestCase("")] + [TestCase(" http://my.local/url")] + [TestCase("http://my.local/url ")] + public void should_report_as_invalid_url(string url) + { + url.IsValidUrl().Should().BeFalse(); + } + } +} diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 80cd14005..cc9445bad 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -83,6 +83,7 @@ + diff --git a/src/NzbDrone.Common/Extensions/UrlExtensions.cs b/src/NzbDrone.Common/Extensions/UrlExtensions.cs index b2dac6c19..50e0b9856 100644 --- a/src/NzbDrone.Common/Extensions/UrlExtensions.cs +++ b/src/NzbDrone.Common/Extensions/UrlExtensions.cs @@ -11,6 +11,11 @@ namespace NzbDrone.Common.Extensions return false; } + if (path.StartsWith(" ") || path.EndsWith(" ")) + { + return false; + } + Uri uri; if (!Uri.TryCreate(path, UriKind.Absolute, out uri)) {