diff --git a/common/functions.php b/common/functions.php index cadda061b..ecdb147f2 100644 --- a/common/functions.php +++ b/common/functions.php @@ -508,8 +508,8 @@ function tobool($input) { if (is_scalar($input)) { - if (preg_match('/^(1|[ty].*|on|ok.*oui|si|vrai|aye)$/i', $input)) return true; - if (preg_match('/^(0|[fn].*|off)$/i', $input)) return false; + if (preg_match('/^(?:1|[ty].*|on|ok.*|oui|si|vrai|aye)$/i', $input)) return true; + if (preg_match('/^(?:0|[fn].*|off|out)$/i', $input)) return false; } return (bool)$input; } diff --git a/tests/unit/functions/FunctionsTest.php b/tests/unit/functions/FunctionsTest.php index c714afddd..528688a6f 100644 --- a/tests/unit/functions/FunctionsTest.php +++ b/tests/unit/functions/FunctionsTest.php @@ -123,18 +123,26 @@ class FunctionsTest extends \Codeception\TestCase\Test $this->assertTrue(tobool('on')); $this->assertTrue(tobool('ok')); $this->assertTrue(tobool('okay')); + $this->assertTrue(tobool('oui')); + $this->assertTrue(tobool('si')); + $this->assertTrue(tobool('vrai')); $this->assertTrue(tobool('true')); $this->assertTrue(tobool(1)); $this->assertTrue(tobool(-1)); $this->assertTrue(tobool(true)); $this->assertTrue(tobool(array(1, 2, 3))); + $this->assertTrue(tobool(new stdClass)); $this->assertFalse(tobool('N')); $this->assertFalse(tobool('no')); + $this->assertFalse(tobool('none')); + $this->assertFalse(tobool('Nobody')); $this->assertFalse(tobool('false')); $this->assertFalse(tobool('off')); + $this->assertFalse(tobool('OUT')); $this->assertFalse(tobool('Fuck you!')); $this->assertFalse(tobool(0)); + $this->assertFalse(tobool(0.00000000)); $this->assertFalse(tobool('')); $this->assertFalse(tobool(false)); $this->assertFalse(tobool(null));