Skip to content

Commit 6e0a6c9

Browse files
committed
Security/ValidatedSanitizedInput: add test with PHP 8.0+ match [1]
When a superglobal is used in a match condition, it doesn't need to be unslashed/sanitized. This is already handled correctly, this just adds a test to safeguard this.
1 parent 57db689 commit 6e0a6c9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.1.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,12 @@ function test_null_coalesce_equals_validation_extra_safeguard() {
480480
$_POST['key'] ??= 'default'; // OK, assignment.
481481
$key = $_POST['key']; // Bad, missing unslash + sanitization, validation okay.
482482
}
483+
484+
function test_in_match_condition_is_regarded_as_comparison() {
485+
if ( isset( $_REQUEST['key'] ) ) {
486+
$test = match( $_REQUEST['key'] ) {
487+
'valueA' => 'A',
488+
default => 'B',
489+
};
490+
}
491+
}

0 commit comments

Comments
 (0)