removed comma from windows invalid path chars.

pull/23/head
Keivan Beigi 12 years ago
parent 566e4eb1ce
commit f162f164e7

@ -0,0 +1,19 @@
using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Test.Common;
namespace NzbDrone.Common.Test.EnsureTest
{
[TestFixture]
public class PathExtensionFixture : TestBase
{
[TestCase(@"p:\TV Shows\file with, comma.mkv")]
public void EnsureWindowsPath(string path)
{
Ensure.That(() => path).IsValidPath();
}
}
}

@ -81,6 +81,7 @@
<Compile Include="CacheTests\CachedManagerFixture.cs" />
<Compile Include="CacheTests\CachedFixture.cs" />
<Compile Include="ConfigFileProviderTest.cs" />
<Compile Include="EnsureTest\PathExtensionFixture.cs" />
<Compile Include="EventingTests\MessageAggregatorCommandTests.cs" />
<Compile Include="EventingTests\MessageAggregatorEventTests.cs" />
<Compile Include="ReflectionExtensions.cs" />

@ -96,7 +96,7 @@ namespace NzbDrone.Common.EnsureThat
return param;
}
private static readonly Regex windowsInvalidPathRegex = new Regex(@"[/,*,<,>,"",|]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex windowsInvalidPathRegex = new Regex(@"[/*<>""|]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex windowsPathRegex = new Regex(@"^[a-z]:\\", RegexOptions.Compiled | RegexOptions.IgnoreCase);
[DebuggerStepThrough]

@ -103,7 +103,7 @@
<Compile Include="EnsureThat\ExpressionExtensions.cs" />
<Compile Include="EnsureThat\Param.cs" />
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
<Compile Include="EnsureThat\StringExtensions.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="EnsureThat\TypeParam.cs" />
<Compile Include="HashUtil.cs" />
<Compile Include="Instrumentation\ApplicationLogLayoutRenderer.cs" />

@ -0,0 +1,39 @@
using System.Text.RegularExpressions;
using System.Linq;
namespace NzbDrone.Common
{
public static class StringExtensions
{
public static string Inject(this string format, params object[] formattingArgs)
{
return string.Format(format, formattingArgs);
}
public static string Inject(this string format, params string[] formattingArgs)
{
return string.Format(format, formattingArgs.Cast<object>());
}
private static readonly Regex InvalidCharRegex = new Regex(@"[^a-z0-9\s-]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex CollapseSpace = new Regex(@"\s+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static string ToSlug(this string phrase)
{
phrase = phrase.RemoveAccent().ToLower();
phrase = InvalidCharRegex.Replace(phrase, string.Empty);
phrase = CollapseSpace.Replace(phrase, " ").Trim();
phrase = phrase.Replace(" ", "-");
return phrase;
}
public static string RemoveAccent(this string txt)
{
var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}
}
}
Loading…
Cancel
Save