From d9b299f1ee249d98ce6f5fd47b43febd087c1441 Mon Sep 17 00:00:00 2001 From: nanaya Date: Wed, 8 Nov 2023 18:07:58 +0900 Subject: [PATCH] Fix inside quotes incorrectly trimmed out --- app/Libraries/Search/BeatmapsetQueryParser.php | 8 ++++---- tests/Libraries/Search/BeatmapsetQueryParserTest.php | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Libraries/Search/BeatmapsetQueryParser.php b/app/Libraries/Search/BeatmapsetQueryParser.php index 4f948e0556a..9570b65571f 100644 --- a/app/Libraries/Search/BeatmapsetQueryParser.php +++ b/app/Libraries/Search/BeatmapsetQueryParser.php @@ -224,11 +224,11 @@ private static function makeIntRangeOption($operator, $value) } } - private static function makeTextOption($operator, $value) + private static function makeTextOption(string $operator, string $value): ?string { - if ($operator === '=') { - return presence(trim($value, '"')); - } + return $operator === '=' + ? presence(preg_replace('/^"(.*)"$/', '$1', $value)) + : null; } private static function statePrefixSearch($value): ?int diff --git a/tests/Libraries/Search/BeatmapsetQueryParserTest.php b/tests/Libraries/Search/BeatmapsetQueryParserTest.php index a51d7f924d6..d2883bb4cca 100644 --- a/tests/Libraries/Search/BeatmapsetQueryParserTest.php +++ b/tests/Libraries/Search/BeatmapsetQueryParserTest.php @@ -92,6 +92,7 @@ public function queryDataProvider() ['find me songs by artist=singer please', ['keywords' => 'find me songs by please', 'options' => ['artist' => 'singer']]], ['really like artist="name with space" yes', ['keywords' => 'really like yes', 'options' => ['artist' => 'name with space']]], ['weird artist=double"quote', ['keywords' => 'weird', 'options' => ['artist' => 'double"quote']]], + ['weird artist="nested "quote"" thing', ['keywords' => 'weird thing', 'options' => ['artist' => 'nested "quote"']]], ['artist=> null, 'options' => ['artist' => '> 'unrecognised=keyword', 'options' => []]], ['cs=nope', ['keywords' => 'cs=nope', 'options' => []]],