Skip to content

Commit b10d739

Browse files
authored
QueryNormalizer: Add support for normalize some UTF-8 characters and special characters by replace table.
1 parent 9c79a6a commit b10d739

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/QueryNormalizer.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ public function __construct(NumberRewriter $numberRewriter)
6767
*/
6868
public function normalize(string $query): string
6969
{
70-
$query = Strings::trim(Strings::normalize($query), " \t\n\r\"'");
70+
$query = trim(Strings::normalize($query), " \t\n\r\"'");
7171
$query = $this->removeEmoji($query);
72-
$query = (string) preg_replace('/\s+/', ' ', $query);
7372
$query = (string) preg_replace('/=\??$/', '', $query);
7473

7574
$queryNew = '';
@@ -82,7 +81,10 @@ public function normalize(string $query): string
8281
$queryNew .= ($queryNew !== '' ? '=' : '') . $queryPart;
8382
}
8483

85-
return $queryNew;
84+
$queryNew = $this->replaceSpecialCharacters($queryNew);
85+
$queryNew = (string) preg_replace('/\s+/', ' ', $queryNew);
86+
87+
return trim($queryNew);
8688
}
8789

8890
/**
@@ -183,4 +185,15 @@ private function removeEmoji(string $query): string
183185
return $query;
184186
}
185187

188+
/**
189+
* @param string $query
190+
* @return string
191+
*/
192+
private function replaceSpecialCharacters(string $query): string
193+
{
194+
$query = str_replace(['½', 'Ã'], [' 1/2', 'á'], $query);
195+
196+
return $query;
197+
}
198+
186199
}

0 commit comments

Comments
 (0)