From 2b6df5f8ce136f76fed149d483ce0e21eea86048 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 3 Nov 2014 15:54:42 +0000 Subject: [PATCH] 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 --- src/wp-includes/functions.php | 6 ++++-- .../tests/functions/WpValidateBoolean.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index dce925a677..8ca5ca17de 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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; } diff --git a/tests/phpunit/tests/functions/WpValidateBoolean.php b/tests/phpunit/tests/functions/WpValidateBoolean.php index 812563757e..38a731e31c 100644 --- a/tests/phpunit/tests/functions/WpValidateBoolean.php +++ b/tests/phpunit/tests/functions/WpValidateBoolean.php @@ -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' ) ); + } }