Merge pull request #90 from awegg/fix_filter_ordering

Fix issue where the order of Filter expressions changed the result.
This commit is contained in:
Ashish Patel 2020-10-23 00:28:14 +05:30 committed by GitHub
commit 9bbc09898e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -44,10 +44,7 @@ namespace Sieve.Models
{
Filter = subfilters + filterOpAndVal
};
if (!value.Any(f => f.Names.Any(n => filterTerm.Names.Any(n2 => n2 == n))))
{
value.Add(filterTerm);
}
value.Add(filterTerm);
}
else
{

View File

@ -352,6 +352,24 @@ namespace SieveUnitTests
Assert.AreEqual(3, entry.Id);
}
[DataTestMethod]
[DataRow("CategoryId==1,(CategoryId|LikeCount)==50")]
[DataRow("(CategoryId|LikeCount)==50,CategoryId==1")]
public void CombinedAndOrFilterIndependentOfOrder(string filter)
{
var model = new SieveModel()
{
Filters = filter,
};
var result = _processor.Apply(model, _posts);
var entry = result.FirstOrDefault();
var resultCount = result.Count();
Assert.IsNotNull(entry);
Assert.AreEqual(1, resultCount);
}
[TestMethod]
public void OrValueFilteringWorks()
{