Catch various validation errors

This commit is contained in:
James Cole
2023-01-20 22:08:18 +01:00
parent 614d54c9bd
commit cd408e581b
7 changed files with 68 additions and 15 deletions

View File

@@ -46,10 +46,11 @@ trait ConvertsDataTypes
* Abstract method that always exists in the Request classes that use this
* trait, OR a stub needs to be added by any other class that uses this train.
*
* @param mixed $key
* @param mixed $key
* @return mixed
*/
abstract public function has($key);
/**
* Return integer value.
*
@@ -71,7 +72,11 @@ trait ConvertsDataTypes
*/
public function convertString(string $field): string
{
return $this->clearString((string)($this->get($field) ?? ''), false);
$entry = $this->get($field);
if (!is_scalar($entry)) {
return '';
}
return $this->clearString((string)$entry, false);
}
/**
@@ -85,7 +90,9 @@ trait ConvertsDataTypes
if (null === $string) {
return null;
}
$search = [
var_dump($string);
$search = [
"\0", // NUL
"\f", // form feed
"\v", // vertical tab
@@ -135,14 +142,17 @@ trait ConvertsDataTypes
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
];
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$secondSearch = $keepNewlines ? ["\r"] : ["\r", "\n", "\t", "\036", "\025"];
$string = str_replace($secondSearch, '', $string);
// clear zalgo text (TODO also in API v2)
$string = preg_replace('/\pM/u', '', $string);
if (null === $string) {
return null;
}
return trim($string);
}