Skip to content

Commit be30b5e

Browse files
committed
Security/ValidatedSanitizedInput: add tests with PHP 8.0+ match [2]
When a superglobal is used in the match return expressions, it should be validated, unslashed and sanitized. This is already handled correctly, this just adds a test to safeguard this.
1 parent 6e0a6c9 commit be30b5e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.1.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,14 @@ function test_in_match_condition_is_regarded_as_comparison() {
489489
};
490490
}
491491
}
492+
493+
function test_in_match_condition_is_regarded_as_comparison() {
494+
if ( isset( $_REQUEST['keyA'], $_REQUEST['keyB'], $_REQUEST['keyC'] ) ) {
495+
$test = match( $toggle ) {
496+
true => sanitize_text_field( wp_unslash( $_REQUEST['keyA'] ) ), // OK.
497+
false => sanitize_text_field( $_REQUEST['keyB'] ), // Bad - missing unslash.
498+
10 => wp_unslash( $_REQUEST['keyC'] ), // Bad - missing sanitization.
499+
default => $_REQUEST['keyD'], // Bad - missing sanitization, unslash, validation.
500+
};
501+
}
502+
}

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function getErrorList( $testFile = '' ) {
111111
475 => 1,
112112
476 => 1,
113113
481 => 2,
114+
497 => 1,
115+
498 => 1,
116+
499 => 3,
114117
);
115118

116119
case 'ValidatedSanitizedInputUnitTest.2.inc':

0 commit comments

Comments
 (0)