Skip to content

Commit 6cd2470

Browse files
committed
Additional fix for deprecated null usage
1 parent bbc48dc commit 6cd2470

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

system/HTTP/IncomingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public function getJsonVar(string $index, bool $assoc = false, ?int $filter = nu
565565
*/
566566
public function getRawInput()
567567
{
568-
parse_str($this->body, $output);
568+
parse_str($this->body ?? '', $output);
569569

570570
return $output;
571571
}

system/Validation/FormatRules.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ public function alpha_space(?string $value = null): bool
4545

4646
/**
4747
* Alphanumeric with underscores and dashes
48+
*
49+
* @see https://regex101.com/r/XfVY3d/1
4850
*/
4951
public function alpha_dash(?string $str = null): bool
5052
{
51-
// @see https://regex101.com/r/XfVY3d/1
52-
return (bool) preg_match('/\A[a-z0-9_-]+\z/i', $str);
53+
if ($str === null) {
54+
return false;
55+
}
56+
57+
return preg_match('/\A[a-z0-9_-]+\z/i', $str) === 1;
5358
}
5459

5560
/**
@@ -59,14 +64,19 @@ public function alpha_dash(?string $str = null): bool
5964
* _ underscore, + plus, = equals, | vertical bar, : colon, . period
6065
* ~ ! # $ % & * - _ + = | : .
6166
*
62-
* @param string $str
67+
* @param string|null $str
6368
*
6469
* @return bool
70+
*
71+
* @see https://regex101.com/r/6N8dDY/1
6572
*/
6673
public function alpha_numeric_punct($str)
6774
{
68-
// @see https://regex101.com/r/6N8dDY/1
69-
return (bool) preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str);
75+
if ($str === null) {
76+
return false;
77+
}
78+
79+
return preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str) === 1;
7080
}
7181

7282
/**
@@ -307,7 +317,7 @@ public function valid_url_strict(?string $str = null, ?string $validSchemes = nu
307317
return false;
308318
}
309319

310-
$scheme = strtolower(parse_url($str, PHP_URL_SCHEME));
320+
$scheme = strtolower(parse_url($str, PHP_URL_SCHEME) ?? ''); // absent scheme gives null
311321
$validSchemes = explode(
312322
',',
313323
strtolower($validSchemes ?? 'http,https')

system/Validation/Rules.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,19 @@ public function not_in_list(?string $value, string $list): bool
213213
*/
214214
public function required($str = null): bool
215215
{
216+
if ($str === null) {
217+
return false;
218+
}
219+
216220
if (is_object($str)) {
217221
return true;
218222
}
219223

220-
return is_array($str) ? ! empty($str) : (trim($str) !== '');
224+
if (is_array($str)) {
225+
return $str !== [];
226+
}
227+
228+
return trim((string) $str) !== '';
221229
}
222230

223231
/**

0 commit comments

Comments
 (0)