Fixed quoting of string literals containing backslash

parent 1b1adc2a
......@@ -21,7 +21,6 @@ use function func_num_args;
use function implode;
use function preg_match;
use function sprintf;
use function str_replace;
use function strlen;
use function strpos;
use function strtoupper;
......@@ -1175,14 +1174,4 @@ SQL
{
return 'BLOB';
}
/**
* {@inheritdoc}
*/
public function quoteStringLiteral($str)
{
$str = str_replace('\\', '\\\\', $str); // Oracle requires backslashes to be escaped aswell.
return parent::quoteStringLiteral($str);
}
}
......@@ -28,7 +28,6 @@ use function is_bool;
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 @@ SQL
return 'BYTEA';
}
/**
* {@inheritdoc}
*/
public function quoteStringLiteral($str)
{
$str = str_replace('\\', '\\\\', $str); // PostgreSQL requires backslashes to be escaped aswell.
return parent::quoteStringLiteral($str);
}
/**
* {@inheritdoc}
*/
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Platform;
use Doctrine\Tests\DbalFunctionalTestCase;
class QuotingTest extends DbalFunctionalTestCase
{
/**
* @dataProvider stringLiteralProvider
*/
public function testQuoteStringLiteral(string $string) : void
{
$platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL(
$platform->quoteStringLiteral($string)
);
self::assertSame($string, $this->connection->fetchColumn($query));
}
/**
* @return mixed[][]
*/
public static function stringLiteralProvider() : iterable
{
return [
'backslash' => ['\\'],
'single-quote' => ["'"],
];
}
}
......@@ -952,7 +952,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
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 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public function testQuotesSchemaNameInListTableForeignKeysSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
'',
true
......@@ -973,7 +973,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
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 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
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 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public function testQuotesSchemaNameInListTableIndexesSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
'',
true
......@@ -1002,7 +1002,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
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 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public function testQuotesSchemaNameInListTableColumnsSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
'',
true
......@@ -1024,7 +1024,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL()
{
self::assertContains(
"'Foo''Bar\\\\'",
"'Foo''Bar\\'",
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"),
'',
true
......
......@@ -875,7 +875,7 @@ SQL
*/
public function testQuotesDatabaseNameInListSequencesSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -883,7 +883,7 @@ SQL
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -891,7 +891,7 @@ SQL
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -899,7 +899,7 @@ SQL
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -907,7 +907,7 @@ SQL
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -915,6 +915,6 @@ SQL
*/
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);
}
}
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