diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 32b12a0bc1f..7a1cd574427 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -36,7 +36,6 @@ use function implode; use function preg_match; use function sprintf; -use function str_replace; use function strlen; use function strpos; use function strtoupper; @@ -1180,14 +1179,4 @@ public function getBlobTypeDeclarationSQL(array $field) { return 'BLOB'; } - - /** - * {@inheritdoc} - */ - public function quoteStringLiteral($str) - { - $str = str_replace('\\', '\\\\', $str); // Oracle requires backslashes to be escaped aswell. - - return parent::quoteStringLiteral($str); - } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 64666b5672b..f7fb1eccdc9 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -42,7 +42,6 @@ use function is_bool; use function is_numeric; use function is_string; -use function str_replace; use function strpos; use function strtolower; use function trim; @@ -1205,16 +1204,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/Platform/QuotingTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php new file mode 100644 index 00000000000..0cf326ad2ae --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php @@ -0,0 +1,32 @@ +_conn->getDatabasePlatform(); + $query = $platform->getDummySelectSQL( + $platform->quoteStringLiteral($string) + ); + + self::assertSame($string, $this->_conn->fetchColumn($query)); + } + + /** + * @return mixed[][] + */ + public static function stringLiteralProvider() : iterable + { + return [ + 'backslash' => ['\\'], + 'single-quote' => ["'"], + ]; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 6732ad339ac..23da589cb1e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -922,7 +922,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); } /** @@ -931,7 +931,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true @@ -943,7 +943,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); } /** @@ -951,7 +951,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); } /** @@ -960,7 +960,7 @@ public function testQuotesTableNameInListTableIndexesSQL() public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true @@ -972,7 +972,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); } /** @@ -981,7 +981,7 @@ public function testQuotesTableNameInListTableColumnsSQL() public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true @@ -994,7 +994,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->_platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), '', true diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 5e270b4a1e7..41adb66df8b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -845,7 +845,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesDatabaseNameInListSequencesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListSequencesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListSequencesSQL("Foo'Bar\\"), '', true); } /** @@ -853,7 +853,7 @@ public function testQuotesDatabaseNameInListSequencesSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -861,7 +861,7 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -869,7 +869,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -877,7 +877,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -885,6 +885,6 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); } }