Skip to content

Commit 57db689

Browse files
committed
Security/ValidatedSanitizedInput: add extra test for PHP 7.4+ null coalesce equals
PR 1684 (WPCS 2.1.0) already took care of the handling of validation via the null coalesce equals assignment operator, but there was one test case missing. This adds that extra test as an additional safeguard.
1 parent d2a52ce commit 57db689

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.1.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,8 @@ function test_examine_additional_superglobals_as_vars() {
475475
do_something( $_ENV['key'] );
476476
do_something( $_FILES['key'] );
477477
}
478+
479+
function test_null_coalesce_equals_validation_extra_safeguard() {
480+
$_POST['key'] ??= 'default'; // OK, assignment.
481+
$key = $_POST['key']; // Bad, missing unslash + sanitization, validation okay.
482+
}

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function getErrorList( $testFile = '' ) {
110110
474 => 1,
111111
475 => 1,
112112
476 => 1,
113+
481 => 2,
113114
);
114115

115116
case 'ValidatedSanitizedInputUnitTest.2.inc':

0 commit comments

Comments
 (0)