Skip to content

Commit

Permalink
Update the code that uses merge array and needs to be lowercased
Browse files Browse the repository at this point in the history
  • Loading branch information
dingo-d committed Sep 18, 2023
1 parent 976c1c5 commit 4556d69
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 81 deletions.
24 changes: 8 additions & 16 deletions WordPress/Helpers/EscapingFunctionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,11 @@ final public function is_escaping_function( $functionName ) {
if ( array() === $this->allEscapingFunctions
|| $this->customEscapingFunctions !== $this->addedCustomEscapingFunctions['escape']
) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_escaping_functions = array_map( 'strtolower', $this->customEscapingFunctions );
$escaping_functions = array_change_key_case( $this->escapingFunctions, \CASE_LOWER );

$this->allEscapingFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_escaping_functions,
$escaping_functions
$this->customEscapingFunctions,
$this->escapingFunctions,
true,
true
);

$this->addedCustomEscapingFunctions['escape'] = $this->customEscapingFunctions;
Expand All @@ -248,15 +244,11 @@ final public function is_auto_escaped_function( $functionName ) {
if ( array() === $this->allAutoEscapedFunctions
|| $this->customAutoEscapedFunctions !== $this->addedCustomEscapingFunctions['autoescape']
) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_auto_escaped_functions = array_map( 'strtolower', $this->customAutoEscapedFunctions );
$auto_escaped_functions = array_change_key_case( $this->autoEscapedFunctions, \CASE_LOWER );

$this->allAutoEscapedFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_auto_escaped_functions,
$auto_escaped_functions
$this->customAutoEscapedFunctions,
$this->autoEscapedFunctions,
true,
true
);

$this->addedCustomEscapingFunctions['autoescape'] = $this->customAutoEscapedFunctions;
Expand Down
10 changes: 3 additions & 7 deletions WordPress/Helpers/IsUnitTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,11 @@ final protected function get_all_test_classes() {
}
}

/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_test_classes = array_map( 'strtolower', $custom_test_classes );
$known_test_classes = array_change_key_case( $this->known_test_classes, \CASE_LOWER );

$this->all_test_classes = RulesetPropertyHelper::merge_custom_array(
$custom_test_classes,
$known_test_classes
$this->known_test_classes,
true,
true
);

// Store the original value so the comparison can succeed.
Expand Down
12 changes: 4 additions & 8 deletions WordPress/Helpers/PrintingFunctionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ final public function get_printing_functions() {
if ( array() === $this->allPrintingFunctions
|| $this->customPrintingFunctions !== $this->addedCustomPrintingFunctions
) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_printing_functions = array_map( 'strtolower', $this->customPrintingFunctions );
$printing_functions = array_change_key_case( $this->printingFunctions, \CASE_LOWER );

$this->allPrintingFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_printing_functions,
$printing_functions
$this->customPrintingFunctions,
$this->printingFunctions,
true,
true
);

$this->addedCustomPrintingFunctions = $this->customPrintingFunctions;
Expand Down
24 changes: 8 additions & 16 deletions WordPress/Helpers/SanitizationHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,11 @@ final public function get_sanitizing_functions() {
if ( array() === $this->allSanitizingFunctions
|| $this->customSanitizingFunctions !== $this->addedCustomSanitizingFunctions['sanitize']
) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_sanitizing_functions = array_map( 'strtolower', $this->customSanitizingFunctions );
$sanitizing_functions = array_change_key_case( $this->sanitizingFunctions, \CASE_LOWER );

$this->allSanitizingFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_sanitizing_functions,
$sanitizing_functions
$this->customSanitizingFunctions,
$this->sanitizingFunctions,
true,
true
);

$this->addedCustomSanitizingFunctions['sanitize'] = $this->customSanitizingFunctions;
Expand All @@ -222,15 +218,11 @@ final public function get_sanitizing_and_unslashing_functions() {
if ( array() === $this->allUnslashingSanitizingFunctions
|| $this->customUnslashingSanitizingFunctions !== $this->addedCustomSanitizingFunctions['unslashsanitize']
) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_unslashing_sanitizing_functions = array_map( 'strtolower', $this->customUnslashingSanitizingFunctions );
$unslashing_sanitizing_functions = array_change_key_case( $this->unslashingSanitizingFunctions, \CASE_LOWER );

$this->allUnslashingSanitizingFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_unslashing_sanitizing_functions,
$unslashing_sanitizing_functions
$this->customUnslashingSanitizingFunctions,
$this->unslashingSanitizingFunctions,
true,
true
);

$this->addedCustomSanitizingFunctions['unslashsanitize'] = $this->customUnslashingSanitizingFunctions;
Expand Down
36 changes: 12 additions & 24 deletions WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,45 +273,33 @@ protected function mergeFunctionLists() {
}

if ( $this->customCacheGetFunctions !== $this->addedCustomFunctions['cacheget'] ) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_cache_get_functions = array_map( 'strtolower', $this->customCacheGetFunctions );
$cache_get_functions = array_change_key_case( $this->cacheGetFunctions, \CASE_LOWER );

$this->cacheGetFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_cache_get_functions,
$cache_get_functions
$this->customCacheGetFunctions,
$this->cacheGetFunctions,
true,
true
);

$this->addedCustomFunctions['cacheget'] = $this->customCacheGetFunctions;
}

if ( $this->customCacheSetFunctions !== $this->addedCustomFunctions['cacheset'] ) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_cache_set_functions = array_map( 'strtolower', $this->customCacheSetFunctions );
$cache_set_functions = array_change_key_case( $this->cacheSetFunctions, \CASE_LOWER );

$this->cacheSetFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_cache_set_functions,
$cache_set_functions
$this->customCacheSetFunctions,
$this->cacheSetFunctions,
true,
true
);

$this->addedCustomFunctions['cacheset'] = $this->customCacheSetFunctions;
}

if ( $this->customCacheDeleteFunctions !== $this->addedCustomFunctions['cachedelete'] ) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_cache_delete_functions = array_map( 'strtolower', $this->customCacheDeleteFunctions );
$cache_delete_functions = array_change_key_case( $this->cacheDeleteFunctions, \CASE_LOWER );

$this->cacheDeleteFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_cache_delete_functions,
$cache_delete_functions
$this->customCacheDeleteFunctions,
$this->cacheDeleteFunctions,
true,
true
);

$this->addedCustomFunctions['cachedelete'] = $this->customCacheDeleteFunctions;
Expand Down
3 changes: 1 addition & 2 deletions WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public function register() {
*/
public function process_token( $stackPtr ) {
// Handle the user-defined custom function list.
$this->customAllowedFunctionsList = RulesetPropertyHelper::merge_custom_array( $this->customAllowedFunctionsList, array(), false );
$this->customAllowedFunctionsList = array_map( 'strtolower', $this->customAllowedFunctionsList );
$this->customAllowedFunctionsList = RulesetPropertyHelper::merge_custom_array( $this->customAllowedFunctionsList, array(), false, true );

/*
* Check if the error silencing is done for one of the allowed functions.
Expand Down
12 changes: 4 additions & 8 deletions WordPress/Sniffs/Security/NonceVerificationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,11 @@ private function set_cache( $filename, $start, $end, $nonce ) {
*/
protected function mergeFunctionLists() {
if ( $this->customNonceVerificationFunctions !== $this->addedCustomNonceFunctions ) {
/*
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
*/
$custom_nonce_verification_functions = array_map( 'strtolower', $this->customNonceVerificationFunctions );
$nonce_verification_functions = array_change_key_case( $this->nonceVerificationFunctions, \CASE_LOWER );

$this->nonceVerificationFunctions = RulesetPropertyHelper::merge_custom_array(
$custom_nonce_verification_functions,
$nonce_verification_functions
$this->customNonceVerificationFunctions,
$this->nonceVerificationFunctions,
true,
true
);

$this->addedCustomNonceFunctions = $this->customNonceVerificationFunctions;
Expand Down

0 comments on commit 4556d69

Please sign in to comment.