From 69e9d5d011a223241c1f24e479a1aa35b7612b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sun, 11 Nov 2018 03:46:52 +0100 Subject: [PATCH] #2926 Fix backslashes double escaping --- .../DBAL/Platforms/PostgreSqlPlatform.php | 11 ------ .../SchemaManagerFunctionalTestCase.php | 37 +++++++++++++++++++ .../AbstractPostgreSqlPlatformTestCase.php | 16 ++++---- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 242c0fd4f28..cb4603f5199 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -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; @@ -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} */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 1c0afc93e66..33cc3b9fec7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -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; @@ -1575,4 +1576,40 @@ 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 +{ + /** + * @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; + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index b7312f376ad..2624de8f71c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -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); } /** @@ -961,7 +961,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true @@ -973,7 +973,7 @@ 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); } /** @@ -981,7 +981,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -990,7 +990,7 @@ public function testQuotesTableNameInListTableIndexesSQL() public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true @@ -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); } /** @@ -1011,7 +1011,7 @@ public function testQuotesTableNameInListTableColumnsSQL() public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true @@ -1024,7 +1024,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), '', true