Skip to content

Additional fix for deprecated null usage #5388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 16 additions & 6 deletions system/Validation/FormatRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 9 additions & 1 deletion system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) !== '';
}

/**
Expand Down