From 7d9b369077dbbacfa2735f08096c3c8a684d8fc2 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 5 Mar 2026 12:29:59 +0100 Subject: [PATCH 1/3] Support int, float and bool values for FilterBy escape --- src/FilterBy.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FilterBy.php b/src/FilterBy.php index 9fba16a8..bc9fb250 100644 --- a/src/FilterBy.php +++ b/src/FilterBy.php @@ -4,8 +4,12 @@ class FilterBy { - public static function escapeString(string $value): string + private function escape(string|int|float|bool $value): string { - return '`' . str_replace('`', '\\`', $value) . '`'; + return match (true) { + is_string($value) => '`' . str_replace('`', '\\`', $value) . '`', + is_bool($value) => $value ? 'true' : 'false', + default => (string) $value, + }; } } From 9c3c63ee055408ab7bea13eb6c8f120c10209975 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 5 Mar 2026 12:31:12 +0100 Subject: [PATCH 2/3] Change escape method to static in FilterBy class --- src/FilterBy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilterBy.php b/src/FilterBy.php index bc9fb250..873a5630 100644 --- a/src/FilterBy.php +++ b/src/FilterBy.php @@ -4,7 +4,7 @@ class FilterBy { - private function escape(string|int|float|bool $value): string + public static function escape(string|int|float|bool $value): string { return match (true) { is_string($value) => '`' . str_replace('`', '\\`', $value) . '`', From da6a6fe23fe5955ba623086e13e2e722e7081f93 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 5 Mar 2026 12:34:04 +0100 Subject: [PATCH 3/3] Refactor escapeString to escape method in tests --- tests/Feature/FilterByTest.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/Feature/FilterByTest.php b/tests/Feature/FilterByTest.php index 3a91603f..ca19e750 100644 --- a/tests/Feature/FilterByTest.php +++ b/tests/Feature/FilterByTest.php @@ -11,7 +11,7 @@ public function testEscapesSpecialCharactersByWrappingInBackticks(): void { $rawFilterValue = "The 17\" O'Conner && O`Series \n OR a || 1%2 book? (draft), [alpha]"; - $escapedFilterValue = FilterBy::escapeString($rawFilterValue); + $escapedFilterValue = FilterBy::escape($rawFilterValue); $this->assertSame( "`The 17\" O'Conner && O\\`Series \n OR a || 1%2 book? (draft), [alpha]`", @@ -21,8 +21,36 @@ public function testEscapesSpecialCharactersByWrappingInBackticks(): void public function testEscapesMultipleBackticksWithinAFilterString(): void { - $escapedFilterValue = FilterBy::escapeString('`left` and `right`'); + $escapedFilterValue = FilterBy::escape('`left` and `right`'); $this->assertSame('`\\`left\\` and \\`right\\``', $escapedFilterValue); } + + public function testEscapeBooleanTrue(): void + { + $escapedFilterValue = FilterBy::escape(true); + + $this->assertSame('true', $escapedFilterValue); + } + + public function testEscapeBooleanFalse(): void + { + $escapedFilterValue = FilterBy::escape(false); + + $this->assertSame('false', $escapedFilterValue); + } + + public function testEscapeFloat(): void + { + $escapedFilterValue = FilterBy::escape(1.12); + + $this->assertSame('1.12', $escapedFilterValue); + } + + public function testEscapeInt(): void + { + $escapedFilterValue = FilterBy::escape(1); + + $this->assertSame('1', $escapedFilterValue); + } }