This commit is contained in:
team 1
2026-05-01 09:24:46 +02:00
parent 0442a24d4c
commit 0c7fca9b46
5 changed files with 128 additions and 97 deletions

View File

@@ -48,6 +48,35 @@ final class CommerceQueryParserConfig
return $this->stringList('filter_search_tokens');
}
/** @return string[] */
private function whitespacePreservingStringList(string $path): array
{
$value = $this->value($path);
if (!is_array($value)) {
throw $this->invalid($path, 'must be a list of non-empty strings');
}
$out = [];
foreach ($value as $item) {
if (!is_scalar($item)) {
continue;
}
$item = (string) $item;
if (trim($item) === '' || in_array($item, $out, true)) {
continue;
}
$out[] = $item;
}
if ($out === []) {
throw $this->invalid($path, 'must contain at least one non-empty string');
}
return $out;
}
/** @return array<string, string> */
public function getSearchTokenCorrections(): array
{
@@ -73,13 +102,13 @@ final class CommerceQueryParserConfig
/** @return string[] */
public function getNormalizationSearch(): array
{
return $this->stringList('normalization.search', true);
return $this->whitespacePreservingStringList('normalization.search');
}
/** @return string[] */
public function getNormalizationReplace(): array
{
return $this->stringList('normalization.replace', true);
return $this->whitespacePreservingStringList('normalization.replace');
}
public function getPromptSanitizePattern(): string
@@ -249,7 +278,7 @@ final class CommerceQueryParserConfig
}
/** @return string[] */
private function stringList(string $path, bool $preserveWhitespace = false): array
private function stringList(string $path): array
{
$value = $this->value($path);
if (!is_array($value)) {
@@ -262,12 +291,9 @@ final class CommerceQueryParserConfig
continue;
}
$item = (string) $item;
if (!$preserveWhitespace) {
$item = trim($item);
}
$item = trim((string) $item);
if (trim($item) === '' || in_array($item, $out, true)) {
if ($item === '' || in_array($item, $out, true)) {
continue;
}