Commit 3de109f2 authored by Davi Koscianski Vidal's avatar Davi Koscianski Vidal Committed by lucasvanlierop

Checking if the boolean string is valid

parent d2995659
......@@ -729,8 +729,17 @@ class PostgreSqlPlatform extends AbstractPlatform
return $callback($value ? true : false);
}
if (is_string($value) && in_array(trim(strtolower($value)), $this->booleanLiterals['false'])) {
return $callback(false);
if (is_string($value)) {
/**
* Better safe than sorry: http://php.net/in_array#106319
*/
if (in_array(trim(strtolower($value)), $this->booleanLiterals['false'], true)) {
return $callback(false);
} elseif (in_array(trim(strtolower($value)), $this->booleanLiterals['true'], true)) {
return $callback(true);
} else {
throw new \UnexpectedValueException("Unrecognized boolean literal '${value}'");
}
}
return $callback(true);
......
......@@ -367,6 +367,15 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$this->assertTrue($platform->convertFromBoolean('1'));
}
/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage Unrecognized boolean literal 'my-bool'
*/
public function testThrowsExceptionWithInvalidBooleanLiteral()
{
$platform = $this->createPlatform()->convertBooleansToDatabaseValue("my-bool");
}
public function testGetCreateSchemaSQL()
{
$schemaName = 'schema';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment