diff --git a/src/Validator.php b/src/Validator.php index efea1220..ebfb4f36 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -101,7 +101,10 @@ public function isBoolean() { return $this->assertNullable( static function (string $value) { - if ($value === '') { + // filter_var() trims its input before matching, so a value that + // is empty only after trimming (eg. whitespace-only) would + // otherwise be treated as the valid boolean false. + if (\trim($value, " \n\r\t\0\x0B") === '') { return false; } diff --git a/tests/Dotenv/ValidatorTest.php b/tests/Dotenv/ValidatorTest.php index 7d4ed3b5..c9654678 100644 --- a/tests/Dotenv/ValidatorTest.php +++ b/tests/Dotenv/ValidatorTest.php @@ -269,6 +269,7 @@ public static function invalidBooleanValuesDataProvider() ['INVALID_SOMETHING'], ['INVALID_EMPTY'], ['INVALID_EMPTY_STRING'], + ['INVALID_WHITESPACE'], ['INVALID_NULL'], ['INVALID_NUMBER_POSITIVE'], ['INVALID_NUMBER_NEGATIVE'], diff --git a/tests/fixtures/env/booleans.env b/tests/fixtures/env/booleans.env index 522ac456..9fbf00c7 100644 --- a/tests/fixtures/env/booleans.env +++ b/tests/fixtures/env/booleans.env @@ -25,6 +25,7 @@ VALID_YESNO_MIXEDCASE_FALSE=No INVALID_SOMETHING=something INVALID_EMPTY= INVALID_EMPTY_STRING="" +INVALID_WHITESPACE=" " INVALID_NULL=null INVALID_NUMBER_POSITIVE=2 INVALID_NUMBER_NEGATIVE=-2