Skip to content

StringFilter not correctly handling all negative search types #383

@markbeazley

Description

@markbeazley

When the StringFilter applies the restriction here it uses orX for every type but TYPE_NOT_EQUAL for which andX is used.

I think andX needs to be used for at least some of if not all of the negative/inverted types, at least TYPE_NOT_CONTAINS and TYPE_NOT_IN.

As an example from Sylius, the product admin grid has a string search on product.code and product.translations.name, if the user picks TYPE_NOT_CONTAINS and searches for Shirt you get a where clause like this WHERE product.code NOT LIKE '%Shirt%' or product.translations.name NOT LIKE '%Shirt%' which would return every product where either the code or the name don't contain the search term, for example say every product just has a numeric code, every code will be true for NOT LIKE '%Shirt%' so every product will be returned.

The bug and any fix will only effect any filters which target multiple fields.

I can look at creating a PR, as it should a a pretty easy fix (just change the if to an in_array check of negative types), the tricky bit (at least to me) is figuring out which types exactly should be switched, there are 3 additional ones I think are likely:

  1. TYPE_NOT_CONTAINS - pretty much needs to be as I think in most cases this is going to give wrong results
  2. TYPE_NOT_IN - similar to 1
  3. TYPE_NOT_EMPTY - I can see this one perhaps working both ways

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions