Check for whitespace in IsValidUrl.

closes #2020
pull/94/head
Taloth Saldono 7 years ago committed by Qstick
parent cf11906118
commit 18971f9ea2

@ -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();
}
}
}

@ -83,6 +83,7 @@
<Compile Include="ExtensionTests\IEnumerableExtensionTests\ExceptByFixture.cs" /> <Compile Include="ExtensionTests\IEnumerableExtensionTests\ExceptByFixture.cs" />
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" /> <Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" /> <Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
<Compile Include="ExtensionTests\UrlExtensionsFixture.cs" />
<Compile Include="HashUtilFixture.cs" /> <Compile Include="HashUtilFixture.cs" />
<Compile Include="Http\HttpClientFixture.cs" /> <Compile Include="Http\HttpClientFixture.cs" />
<Compile Include="Http\HttpHeaderFixture.cs" /> <Compile Include="Http\HttpHeaderFixture.cs" />

@ -11,6 +11,11 @@ namespace NzbDrone.Common.Extensions
return false; return false;
} }
if (path.StartsWith(" ") || path.EndsWith(" "))
{
return false;
}
Uri uri; Uri uri;
if (!Uri.TryCreate(path, UriKind.Absolute, out uri)) if (!Uri.TryCreate(path, UriKind.Absolute, out uri))
{ {

Loading…
Cancel
Save