From d1276bb20e4265309ea2655c8fd9209b74282f81 Mon Sep 17 00:00:00 2001 From: wubinworks <127310257+wubinworks@users.noreply.github.com> Date: Sat, 11 Jan 2025 21:32:52 +0900 Subject: [PATCH 1/3] Fix admin grid filter backslash escaping issue https://github.com/magento/magento2/issues/39513 --- app/code/Magento/Ui/Component/Filters/Type/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index d9e27fae8201d..0dbc17cbb9e4a 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -74,7 +74,7 @@ protected function applyFilter(): void $valueExpression = $filterConfig['valueExpression'] ?? null; } if ($conditionType === self::CONDITION_LIKE) { - $value = str_replace(['%', '_'], ['\%', '\_'], $value); + $value = str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], $value); $valueExpression = $valueExpression ?? '%%%s%%'; } if ($valueExpression) { From 478031fe208f9ed4123572e762b6505317988df7 Mon Sep 17 00:00:00 2001 From: wubinworks <127310257+wubinworks@users.noreply.github.com> Date: Fri, 27 Jun 2025 02:19:04 +0900 Subject: [PATCH 2/3] Add Unit Tests to verify backslash handling and fix Static Tests failure --- .../Magento/Ui/Component/Filters/Type/Input.php | 4 ++-- .../Test/Unit/Component/Filters/Type/InputTest.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index 0dbc17cbb9e4a..661f1c18b6564 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -1,7 +1,7 @@ '%\%%', ], ], + [ + [ + 'name' => 'test_date', + ], + ['test_date' => 'some\\value'], + [ + 'setConditionType' => 'like', + 'setValue' => '%some\\\\value%', + ], + ], [ [ 'name' => 'text_attr', From 26a7fb73f8d0fd6c76fe4f2b70bfad841b8eb1cc Mon Sep 17 00:00:00 2001 From: wubinworks <127310257+wubinworks@users.noreply.github.com> Date: Mon, 30 Jun 2025 12:35:43 +0900 Subject: [PATCH 3/3] Fix Static Tests failure --- .../Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index 651f661d552af..454484dcfa51e 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -172,7 +172,10 @@ public function testPrepare(array $data, array $filterData, ?array $expectedCond } /** + * SuppressWarnings was added due to the big size of data provider + * * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public static function getPrepareDataProvider(): array {