From 4556d69781ec57be2567dfe43f762e25bd4c69fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Mon, 18 Sep 2023 15:03:42 +0200 Subject: [PATCH] Update the code that uses merge array and needs to be lowercased --- WordPress/Helpers/EscapingFunctionsTrait.php | 24 +++++-------- WordPress/Helpers/IsUnitTestTrait.php | 10 ++---- WordPress/Helpers/PrintingFunctionsTrait.php | 12 +++---- WordPress/Helpers/SanitizationHelperTrait.php | 24 +++++-------- .../Sniffs/DB/DirectDatabaseQuerySniff.php | 36 +++++++------------ .../Sniffs/PHP/NoSilencedErrorsSniff.php | 3 +- .../Security/NonceVerificationSniff.php | 12 +++---- 7 files changed, 40 insertions(+), 81 deletions(-) diff --git a/WordPress/Helpers/EscapingFunctionsTrait.php b/WordPress/Helpers/EscapingFunctionsTrait.php index cdef43119b..c6fcc3c209 100644 --- a/WordPress/Helpers/EscapingFunctionsTrait.php +++ b/WordPress/Helpers/EscapingFunctionsTrait.php @@ -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; @@ -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; diff --git a/WordPress/Helpers/IsUnitTestTrait.php b/WordPress/Helpers/IsUnitTestTrait.php index a6e3b36d32..b5e715bb90 100644 --- a/WordPress/Helpers/IsUnitTestTrait.php +++ b/WordPress/Helpers/IsUnitTestTrait.php @@ -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. diff --git a/WordPress/Helpers/PrintingFunctionsTrait.php b/WordPress/Helpers/PrintingFunctionsTrait.php index 330b811241..94c034c419 100644 --- a/WordPress/Helpers/PrintingFunctionsTrait.php +++ b/WordPress/Helpers/PrintingFunctionsTrait.php @@ -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; diff --git a/WordPress/Helpers/SanitizationHelperTrait.php b/WordPress/Helpers/SanitizationHelperTrait.php index df49ebd1f9..ce29ea9e28 100644 --- a/WordPress/Helpers/SanitizationHelperTrait.php +++ b/WordPress/Helpers/SanitizationHelperTrait.php @@ -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; @@ -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; diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index fe99e6a6f3..11cf0796e5 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -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; diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index 4817f82652..a8fe7409c7 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -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. diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 5c893d88c0..60c2e0bb6f 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -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;