From 7b06add05a2bc2adf30281da1d66333357dbe992 Mon Sep 17 00:00:00 2001 From: Vlad Byndych Date: Wed, 10 Jan 2024 18:39:20 +0100 Subject: [PATCH] fix: escaped special characters which could be interpreted incorrectly within regex. --- .../starsql/search/Command/RegexCommand.php | 11 +++++ .../model/persistence/starsql/ClassTest.php | 48 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/core/kernel/persistence/starsql/search/Command/RegexCommand.php b/core/kernel/persistence/starsql/search/Command/RegexCommand.php index 87552adec..5175dfb5c 100644 --- a/core/kernel/persistence/starsql/search/Command/RegexCommand.php +++ b/core/kernel/persistence/starsql/search/Command/RegexCommand.php @@ -73,6 +73,17 @@ public function escapeString($values): string trim($values, '%'), [ '.' => '\\.', + '+' => '\\+', + '?' => '\\?', + '[' => '\\[', + ']' => '\\]', + '(' => '\\(', + ')' => '\\)', + '{' => '\\{', + '}' => '\\}', + '^' => '\\^', + '$' => '\\$', + '|' => '\\|', '\\_' => '_', '\\%' => '%', '*' => '.*', diff --git a/test/integration/model/persistence/starsql/ClassTest.php b/test/integration/model/persistence/starsql/ClassTest.php index 87780492b..cd28712f5 100755 --- a/test/integration/model/persistence/starsql/ClassTest.php +++ b/test/integration/model/persistence/starsql/ClassTest.php @@ -345,6 +345,54 @@ public function dataProviderSearchInstancesWithRegularExpressions(): iterable 'incorrectLabel' => 'test case instance with special ymbols', 'searchCriterion' => 'w\_th \%pecial \%ymbols', ]; + + yield 'regexp plus symbols' => [ + 'correctLabel' => 'application/qti+xml', + 'incorrectLabel' => 'application/qtiiiiixml', + 'searchCriterion' => 'application/qti+xml', + ]; + + yield 'regexp question mark symbols' => [ + 'correctLabel' => 'test case instance with question?', + 'incorrectLabel' => 'test case instance with question!', + 'searchCriterion' => '*question?*', + ]; + + yield 'regexp square brackets symbols' => [ + 'correctLabel' => 'test case instance with [abc]', + 'incorrectLabel' => 'test case instance with c', + 'searchCriterion' => '*with [abc]*', + ]; + + yield 'regexp round brackets symbols' => [ + 'correctLabel' => 'test case instance with (brackets)', + 'incorrectLabel' => 'test case instance with brackets', + 'searchCriterion' => '*with (brackets)*', + ]; + + yield 'regexp curly brackets symbols' => [ + 'correctLabel' => 'test case instance with{1,2}', + 'incorrectLabel' => 'test case instance withh', + 'searchCriterion' => '*with{1,2}*', + ]; + + yield 'regexp dollar symbols' => [ + 'correctLabel' => 'test case instance with$', + 'incorrectLabel' => 'test case instance with', + 'searchCriterion' => '*with$', + ]; + + yield 'regexp caret symbols' => [ + 'correctLabel' => '^test case instance with', + 'incorrectLabel' => 'test case instance with', + 'searchCriterion' => '^test*', + ]; + + yield 'regexp pipe symbols' => [ + 'correctLabel' => 'test case instance with|pipe', + 'incorrectLabel' => 'test case instance with', + 'searchCriterion' => '*with|pipe*', + ]; } /**