Skip to content

Commit c7c7e2d

Browse files
committed
WP/EnqueuedResourceParameters: fix handling of non-lowercased null
This commit fixes how the sniff handles non-lowercased `null` when passed as the value of the `$ver` parameter. Now the sniff consistently handles `null` regardless of the case and always returns a warning. Before, it would return a warning only for lower-cased `null` and an error for all other variations of `null`.
1 parent 22e4f55 commit c7c7e2d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
141141
}
142142
}
143143

144-
if ( false === $version_param || 'null' === $version_param['clean'] ) {
144+
if ( false === $version_param || 'null' === strtolower( $version_param['clean'] ) ) {
145145
$type = 'script';
146146
if ( strpos( $matched_content, '_style' ) !== false ) {
147147
$type = 'style';

WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.1.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array
9595
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (double) 0, true ); // Error - 0, false or NULL are not allowed.
9696

9797
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (binary) 0, true ); // Error - 0, false or NULL are not allowed.
98+
99+
// Safeguard handling of non-lowercase `null`.
100+
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), NULL, true ); // Warning - 0, false or NULL are not allowed.

WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ public function getWarningList( $testFile = '' ) {
7070
switch ( $testFile ) {
7171
case 'EnqueuedResourceParametersUnitTest.1.inc':
7272
return array(
73-
3 => 2,
74-
11 => 1,
75-
32 => 1,
76-
39 => 2,
77-
42 => 1,
78-
45 => 1,
79-
66 => 2,
80-
77 => 1,
73+
3 => 2,
74+
11 => 1,
75+
32 => 1,
76+
39 => 2,
77+
42 => 1,
78+
45 => 1,
79+
66 => 2,
80+
77 => 1,
81+
100 => 1,
8182
);
8283

8384
default:

0 commit comments

Comments
 (0)