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

Fixed quoting of string literals containing backslash #3330

Merged
merged 1 commit into from
Nov 12, 2018
Merged
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/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function implode;
use function preg_match;
use function sprintf;
use function str_replace;
use function strlen;
use function strpos;
use function strtoupper;
Expand Down Expand Up @@ -1175,14 +1174,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);
}
}
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
32 changes: 32 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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' => ["'"],
];
}
}
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
12 changes: 6 additions & 6 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,46 +875,46 @@ 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);
}

/**
* @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);
}

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

/**
* @group DBAL-2436
*/
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 testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
}

/**
* @group DBAL-2436
*/
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);
ostrolucky marked this conversation as resolved.
Show resolved Hide resolved
}
}