Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2926 Fix backslashes double escaping #3342

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use function is_numeric;
use function is_string;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
use function trim;
Expand Down Expand Up @@ -1199,16 +1198,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,41 @@ 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);
$this->connection->getDatabasePlatform()->markDoctrineTypeCommented('Foo\\Bar');

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

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

class BackSlashType extends Type
{
/**
* @param mixed[] $fieldDeclaration
*/
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