Skip to content

Commit 8ba7ccf

Browse files
committed
Update the escaping functions trait
Split the merge function to merge lowercased method/function names, because PHP is case insensitive for all class, namespace and method names.
1 parent 000c105 commit 8ba7ccf

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

WordPress/Helpers/EscapingFunctionsTrait.php

+17-10
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,21 @@ final public function is_escaping_function( $functionName ) {
218218
if ( array() === $this->allEscapingFunctions
219219
|| $this->customEscapingFunctions !== $this->addedCustomEscapingFunctions['escape']
220220
) {
221+
/*
222+
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
223+
*/
224+
$custom_escaping_functions = array_map( 'strtolower', $this->customEscapingFunctions );
225+
$escaping_functions = array_change_key_case( $this->escapingFunctions, \CASE_LOWER );
226+
221227
$this->allEscapingFunctions = RulesetPropertyHelper::merge_custom_array(
222-
$this->customEscapingFunctions,
223-
$this->escapingFunctions
228+
$custom_escaping_functions,
229+
$escaping_functions
224230
);
225231

226232
$this->addedCustomEscapingFunctions['escape'] = $this->customEscapingFunctions;
227233
}
228234

229-
// Check if the $functionName is a static method or not.
230-
if ( strpos( $functionName, '::' ) === false ) {
231-
$functionName = strtolower( $functionName );
232-
}
233-
234-
return isset( $this->allEscapingFunctions[ $functionName ] );
235+
return isset( $this->allEscapingFunctions[ strtolower( $functionName ) ] );
235236
}
236237

237238
/**
@@ -247,9 +248,15 @@ final public function is_auto_escaped_function( $functionName ) {
247248
if ( array() === $this->allAutoEscapedFunctions
248249
|| $this->customAutoEscapedFunctions !== $this->addedCustomEscapingFunctions['autoescape']
249250
) {
251+
/*
252+
* Lowercase all names, both custom as well as "known", as PHP treats namespaced names case-insensitively.
253+
*/
254+
$custom_auto_escaped_functions = array_map( 'strtolower', $this->customAutoEscapedFunctions );
255+
$auto_escaped_functions = array_change_key_case( $this->autoEscapedFunctions, \CASE_LOWER );
256+
250257
$this->allAutoEscapedFunctions = RulesetPropertyHelper::merge_custom_array(
251-
$this->customAutoEscapedFunctions,
252-
$this->autoEscapedFunctions
258+
$custom_auto_escaped_functions,
259+
$auto_escaped_functions
253260
);
254261

255262
$this->addedCustomEscapingFunctions['autoescape'] = $this->customAutoEscapedFunctions;

0 commit comments

Comments
 (0)