Skip to content

Commit

Permalink
doctrine#2926 Fix backslashes double escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 11, 2018
1 parent 822d970 commit d9ed4cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
10 changes: 0 additions & 10 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,16 +1199,6 @@ public function getBlobTypeDeclarationSQL(array $field)
return 'BYTEA';
}

/**
* {@inheritdoc}
*/
public function quoteStringLiteral($str)
{
$str = str_replace('\\', '\\\\', $str); // PostgreSQL requires backslashes to be escaped aswell.

return parent::quoteStringLiteral($str);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
Expand Down Expand Up @@ -1575,4 +1576,37 @@ public function testGenerateAnIndexWithPartialColumnLength() : void
$onlineTable = $this->schemaManager->listTableDetails('test_partial_column_index');
self::assertEquals($expected, $onlineTable->getIndexes());
}

/**
* @group DBAL-2926
* @doesNotPerformAssertions
*/
public function testCanCreateAndRetrieveInfoAboutTypeWithBackslashes()
{
Type::addType('Foo\\Bar', BackSlashType::class);

$table = new Table('test_escaping');
$table->addColumn('column', 'Foo\\Bar');

$this->schemaManager->dropAndCreateTable($table);
$this->schemaManager->listTableColumns('test_escaping');
}
}

class BackSlashType extends Type
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}

public function getName()
{
return 'Foo\\Bar';
}

public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL()
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
}

/**
Expand All @@ -961,7 +961,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL()
public function testQuotesSchemaNameInListTableForeignKeysSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
'',
true
Expand All @@ -973,15 +973,15 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL()
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
}

/**
* @group DBAL-2436
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
}

/**
Expand All @@ -990,7 +990,7 @@ public function testQuotesTableNameInListTableIndexesSQL()
public function testQuotesSchemaNameInListTableIndexesSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
'',
true
Expand All @@ -1002,7 +1002,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL()
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
}

/**
Expand All @@ -1011,7 +1011,7 @@ public function testQuotesTableNameInListTableColumnsSQL()
public function testQuotesSchemaNameInListTableColumnsSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
'',
true
Expand All @@ -1024,7 +1024,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL()
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"),
'',
true
Expand Down

0 comments on commit d9ed4cf

Please sign in to comment.