alirezanet / Gridify

Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
https://alirezanet.github.io/Gridify/
MIT License
807 stars 64 forks source link

Filtering for null/empty case insensitive #171

Open brendonparker opened 3 months ago

brendonparker commented 3 months ago

Version

2.14.1

Details

Thanks for this great library! It really is awesome!

When I attempt to submit a filter like: name=/i an exception is thrown:

Gridify.GridifyFilteringException: 'Unexpected token at index 7, expected '

I'm using gridify-client on the front-end to construct the filter.

I can (and have) changed my code around this to prevent this state/combination of CI + Empty. But seems this could be better handled either by the Gridify code or gridify-client code.

IMO the case-insensitive (/i) should just be ignored in this scenario, and no exception should be thrown.

Steps to reproduce

Failing test (throws an exception):

[Fact] // issue #??
public void ApplyFiltering_CaseInsensitiveEmptyFields_ShouldFilter()
{
   var actual = _fakeRepository.AsQueryable().ApplyFiltering("name=/i").ToList();
   var expected = _fakeRepository.Where(q => string.IsNullOrEmpty(q.Name)).ToList();

   Assert.Equal(expected.Count, actual.Count);
   Assert.Equal(expected, actual);
   Assert.True(actual.Any());
}
alirezanet commented 3 months ago

Hello @brendonparker, Thank you for the positive feedback regarding the library. I'm pleased to know you find it beneficial. Great catch! I will aim to resolve this issue in the upcoming version.

hershi9 commented 1 month ago

@alirezanet Thank you for this great library, it's really awesome! It appears that the use of parentheses, for instance, ?filter=address=ad/i,(room=/i|category=*/i) throws a Gridify.GridifyFilteringException: Unexpected token CaseInsensitive at index 23, expected CloseParenthesis error. Is this a bug or an expected behaviour?

alirezanet commented 1 month ago

Hi @hershi9, I believe this is a bug, would be nice if you could create a separate issue for this.

UPDATE: I reopened this issue. no need to create another one thanks