mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Catch various validation errors
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user