Skip to content

Commit d25f87b

Browse files
authored
Merge pull request #9699 from ddevsr/deprecated-filter-default
refactor: deprecated PHP 8.5 constant `FILTER_DEFAULT` for `filter_*()`
2 parents 97a5462 + cbea67a commit d25f87b

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

rector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Rector\PHPUnit\CodeQuality\Rector\Class_\RemoveDataProviderParamKeysRector;
3939
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
4040
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
41+
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
4142
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
4243
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
4344
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
@@ -205,4 +206,7 @@
205206
// keep '\\' prefix string on string '\Foo\Bar'
206207
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
207208
])
209+
->withConfiguredRule(RenameConstantRector::class, [
210+
'FILTER_DEFAULT' => 'FILTER_UNSAFE_RAW',
211+
])
208212
->withCodeQualityLevel(34);

system/HTTP/IncomingRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,10 @@ public function getJsonVar($index = null, bool $assoc = false, ?int $filter = nu
572572
return null;
573573
}
574574

575-
$filter ??= FILTER_DEFAULT;
575+
$filter ??= FILTER_UNSAFE_RAW;
576576
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);
577577

578-
if ($filter !== FILTER_DEFAULT
578+
if ($filter !== FILTER_UNSAFE_RAW
579579
|| (
580580
(is_numeric($flags) && $flags !== 0)
581581
|| is_array($flags) && $flags !== []
@@ -656,12 +656,12 @@ public function getRawInputVar($index = null, ?int $filter = null, $flags = null
656656
[$output, $data] = [$data, null];
657657
}
658658

659-
$filter ??= FILTER_DEFAULT;
659+
$filter ??= FILTER_UNSAFE_RAW;
660660
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);
661661

662662
if (is_array($output)
663663
&& (
664-
$filter !== FILTER_DEFAULT
664+
$filter !== FILTER_UNSAFE_RAW
665665
|| (
666666
(is_numeric($flags) && $flags !== 0)
667667
|| is_array($flags) && $flags !== []

system/HTTP/RequestTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
260260
}
261261

262262
// Null filters cause null values to return.
263-
$filter ??= FILTER_DEFAULT;
263+
$filter ??= FILTER_UNSAFE_RAW;
264264
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);
265265

266266
// Return all values when $index is null
@@ -312,7 +312,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
312312

313313
if (is_array($value)
314314
&& (
315-
$filter !== FILTER_DEFAULT
315+
$filter !== FILTER_UNSAFE_RAW
316316
|| (
317317
(is_numeric($flags) && $flags !== 0)
318318
|| is_array($flags) && $flags !== []

system/Helpers/cookie_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
8888
}
8989

9090
$request = service('request');
91-
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_DEFAULT;
91+
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_UNSAFE_RAW;
9292

9393
return $request->getCookie($prefix . $index, $filter);
9494
}

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ public static function provideCanGrabGetRawInputVar(): iterable
607607
null,
608608
null,
609609
],
610+
[
611+
'username=admin001&role=administrator&usepass=0',
612+
'username',
613+
'admin001',
614+
null,
615+
FILTER_UNSAFE_RAW,
616+
],
610617
[
611618
'username=admin001&role=administrator&usepass=0',
612619
['role', 'usepass'],

0 commit comments

Comments
 (0)