Ignore case when checking string 'false' in `wp_validate_boolean()`.

Props TobiasBg, kitchin.
Fixes #30238.

git-svn-id: https://develop.svn.wordpress.org/trunk@30207 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2014-11-03 15:54:42 +00:00
parent 1219355f2b
commit 2b6df5f8ce
2 changed files with 20 additions and 2 deletions

View File

@ -4740,7 +4740,9 @@ function reset_mbstring_encoding() {
}
/**
* Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).
* Filter/validate a variable as a boolean.
*
* Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
* @since 4.0.0
*
@ -4752,7 +4754,7 @@ function wp_validate_boolean( $var ) {
return $var;
}
if ( 'false' === $var ) {
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
return false;
}

View File

@ -56,4 +56,20 @@ class Tests_Functions_WpValidateBoolean extends WP_UnitTestCase {
// Differs from (bool) conversion.
$this->assertFalse( wp_validate_boolean( 'false' ) );
}
/**
* @ticket 30238
*/
public function test_string_false_uppercase() {
// Differs from (bool) conversion.
$this->assertFalse( wp_validate_boolean( 'FALSE' ) );
}
/**
* @ticket 30238
*/
public function test_string_false_mixedcase() {
// Differs from (bool) conversion.
$this->assertFalse( wp_validate_boolean( 'FaLsE' ) );
}
}