Skip to content
Browse files

Fix null not being regarded as a valid filter

  • Loading branch information...
1 parent f99bc72 commit 70eed6fc769ad18f957a37047a4aeab1b7a73fd2 @jfreilly jfreilly committed
Showing with 31 additions and 22 deletions.
  1. +18 −20 src/Core/NameFilter.cs
  2. +13 −2 tests/Core/Core.cs
View
38 src/Core/NameFilter.cs
@@ -97,31 +97,29 @@ public static bool IsValidExpression(string expression)
/// <returns>True if the expression is valid, false otherwise.</returns>
public static bool IsValidFilterExpression(string toTest)
{
- if ( toTest == null ) {
- throw new ArgumentNullException("toTest");
- }
-
bool result = true;
try {
- string[] items = SplitQuoted(toTest);
- for (int i = 0; i < items.Length; ++i) {
- if ((items[i] != null) && (items[i].Length > 0)) {
- string toCompile;
+ if (toTest != null) {
+ string[] items = SplitQuoted(toTest);
+ for (int i = 0; i < items.Length; ++i) {
+ if ((items[i] != null) && (items[i].Length > 0)) {
+ string toCompile;
- if (items[i][0] == '+') {
- toCompile = items[i].Substring(1, items[i].Length - 1);
- }
- else if (items[i][0] == '-') {
- toCompile = items[i].Substring(1, items[i].Length - 1);
- }
- else {
- toCompile = items[i];
- }
+ if (items[i][0] == '+') {
+ toCompile = items[i].Substring(1, items[i].Length - 1);
+ }
+ else if (items[i][0] == '-') {
+ toCompile = items[i].Substring(1, items[i].Length - 1);
+ }
+ else {
+ toCompile = items[i];
+ }
- Regex testRegex = new Regex(toCompile, RegexOptions.IgnoreCase | RegexOptions.Singleline);
- }
- }
+ Regex testRegex = new Regex(toCompile, RegexOptions.IgnoreCase | RegexOptions.Singleline);
+ }
+ }
+ }
}
catch (ArgumentException) {
result = false;
View
15 tests/Core/Core.cs
@@ -33,11 +33,22 @@ public void FilterQuoting()
}
}
+ [Test]
+ public void NullFilter()
+ {
+ NameFilter nf = new NameFilter(null);
+ Assert.IsTrue(nf.IsIncluded("o78i6bgv5rvu\\kj//&*"));
+ }
+
[Test]
public void ValidFilter()
{
- Assert.IsTrue(NameFilter.IsValidFilterExpression("a"));
- Assert.IsFalse(NameFilter.IsValidFilterExpression(@"\,)"));
+ Assert.IsTrue(NameFilter.IsValidFilterExpression(null));
+ Assert.IsTrue(NameFilter.IsValidFilterExpression(string.Empty));
+ Assert.IsTrue(NameFilter.IsValidFilterExpression("a"));
+
+ Assert.IsFalse(NameFilter.IsValidFilterExpression(@"\,)"));
+ Assert.IsFalse(NameFilter.IsValidFilterExpression(@"[]"));
}
}
}

0 comments on commit 70eed6f

Please sign in to comment.
Something went wrong with that request. Please try again.