diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 3ac25b6df5fd..76b0c1d1c40a 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -565,7 +565,7 @@ public function getJsonVar(string $index, bool $assoc = false, ?int $filter = nu */ public function getRawInput() { - parse_str($this->body, $output); + parse_str($this->body ?? '', $output); return $output; } diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index e28f6d6af13d..4d02f221365d 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -45,11 +45,16 @@ public function alpha_space(?string $value = null): bool /** * Alphanumeric with underscores and dashes + * + * @see https://regex101.com/r/XfVY3d/1 */ public function alpha_dash(?string $str = null): bool { - // @see https://regex101.com/r/XfVY3d/1 - return (bool) preg_match('/\A[a-z0-9_-]+\z/i', $str); + if ($str === null) { + return false; + } + + return preg_match('/\A[a-z0-9_-]+\z/i', $str) === 1; } /** @@ -59,14 +64,19 @@ public function alpha_dash(?string $str = null): bool * _ underscore, + plus, = equals, | vertical bar, : colon, . period * ~ ! # $ % & * - _ + = | : . * - * @param string $str + * @param string|null $str * * @return bool + * + * @see https://regex101.com/r/6N8dDY/1 */ public function alpha_numeric_punct($str) { - // @see https://regex101.com/r/6N8dDY/1 - return (bool) preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str); + if ($str === null) { + return false; + } + + return preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str) === 1; } /** @@ -307,7 +317,7 @@ public function valid_url_strict(?string $str = null, ?string $validSchemes = nu return false; } - $scheme = strtolower(parse_url($str, PHP_URL_SCHEME)); + $scheme = strtolower(parse_url($str, PHP_URL_SCHEME) ?? ''); // absent scheme gives null $validSchemes = explode( ',', strtolower($validSchemes ?? 'http,https') diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 367915ebae35..aba9ff117df6 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -213,11 +213,19 @@ public function not_in_list(?string $value, string $list): bool */ public function required($str = null): bool { + if ($str === null) { + return false; + } + if (is_object($str)) { return true; } - return is_array($str) ? ! empty($str) : (trim($str) !== ''); + if (is_array($str)) { + return $str !== []; + } + + return trim((string) $str) !== ''; } /**