-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Issue:
LIKE
filters don't work on Magento\Framework\Data\Collection\Filesystem
instances.
How I got here:
I was playing around with the Magento_Backup
module for learning purposes. I saw that in the grid of backups, the Name
column is not filtrable and started digging to see why.
I removed this line <argument name="filter" xsi:type="string">0</argument>
from app/code/Magento/Backup/view/adminhtml/layout/backup_index_block.xml
for the display_name
column and got 2 things out of it.
- The column became filerable
- I understood why the column was not filterable in the first place. Because the LIKE filter does not work.
Afters some debugging I found out why. It's because of the regular expression from Magento\Framework\Data\Collection\Filesystem::filterCallbackLike
.
Scenario.
I search by name for the text 'a'. This transforms into the condition value '%a%'
. (Notice the single quotes before and after the expression).
After calling $filterValueRegex = str_replace('%', '(.*?)', preg_quote($filterValue, '/'));
the regular expression becomes '(.*?)a(.*?)'
. Notice again the single quotes wrapping the expression.
I have 2 backup files called aa
and bb
. Neither of them is matched by the regex but I was expecting aa
to be matched.
Removing the single quotes from the regular expression seams to solve the problem.
so this:
$filterValueRegex = str_replace('%', '(.*?)', preg_quote($filterValue, '/'));
Becomes this:
$filterValueRegex = str_replace(['%', "'"], ['(.*?)',''], preg_quote($filterValue, '/'));
Before doing a pull request, I want to get this by you to get a second opinion.
On the same topic
I noticed that the column Size (bytes)
it's not filterable either. I haven't investigated, but I bet it's for the same reason. This should be an 'int' column and I bet the from-to
filter doesn't work either. But I may be wrong. I'll post more as soon as I have solid evidence.