Search/Fixup

* partially revert eb70065e0f as the
   regex without the /u flag destroys valid umlauts like 'ß'
 * convert strings from utf8 to utf8 instead to achieve the same effect
This commit is contained in:
Sarjuuk 2025-12-26 17:13:29 +01:00
parent 8f9acedb8f
commit 9bbe95d5e8
3 changed files with 9 additions and 5 deletions

View file

@ -76,7 +76,7 @@ class SearchBaseResponse extends TemplateResponse implements ICache
if (($canRedirect && $redirectTo) || count($lvData[0]['data']) > 1)
$canRedirect = false;
if ($canRedirect) // note - we are very lucky that in case of searches $template is identical to the typeString
if ($canRedirect) // note - we are very lucky that in case of searches $template is identical to the typeString
$redirectTo = '?'.$lvData[1].'='.key($lvData[0]['data']);
}
}

View file

@ -456,8 +456,8 @@ trait TrProfilerList
abstract class BaseResponse
{
protected const PATTERN_TEXT_LINE = '/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/i';
protected const PATTERN_TEXT_BLOB = '/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/i';
protected const PATTERN_TEXT_LINE = '/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/iu';
protected const PATTERN_TEXT_BLOB = '/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/iu';
protected static array $sql = []; // debug: sql stats container
@ -637,14 +637,17 @@ abstract class BaseResponse
protected static function checkTextLine(string $val) : string
{
// remove invalid characters
$val = mb_convert_encoding(trim($val), 'utf-8', 'utf-8');
// trim non-printable chars
return preg_replace(self::PATTERN_TEXT_LINE, '', trim($val));
return preg_replace(self::PATTERN_TEXT_LINE, '', $val);
}
protected static function checkTextBlob(string $val) : string
{
$val = mb_convert_encoding(trim($val), 'utf-8', 'utf-8');
// trim non-printable chars + excessive whitespaces (pattern includes \r)
$str = preg_replace(self::PATTERN_TEXT_BLOB, '', trim($val));
$str = preg_replace(self::PATTERN_TEXT_BLOB, '', $val);
return preg_replace('/ +/', ' ', trim($str));
}

View file

@ -3,6 +3,7 @@
namespace Aowow;
mb_internal_encoding('UTF-8');
mb_substitute_character('none'); // drop invalid chars entirely instead of replacing them with '?'
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR);