1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Check for whitespace in IsValidUrl.

closes #2020
This commit is contained in:
Taloth Saldono 2017-07-22 22:14:06 +02:00
parent 4b9f2e0ff7
commit 792773323c
3 changed files with 35 additions and 0 deletions

View File

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

View File

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

View File

@ -11,6 +11,11 @@ public static bool IsValidUrl(this string path)
return false;
}
if (path.StartsWith(" ") || path.EndsWith(" "))
{
return false;
}
Uri uri;
if (!Uri.TryCreate(path, UriKind.Absolute, out uri))
{