Skip to content

Commit

Permalink
[doctrineGH-4645] Fix SQLServerPlatform::quoteIdentifier()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed May 13, 2021
1 parent b728198 commit 8809142
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ protected function getReservedKeywordsClass()
*/
public function quoteSingleIdentifier($str)
{
return '[' . str_replace(']', '][', $str) . ']';
return '[' . str_replace(']', ']]', $str) . ']';
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\Tests\DbalFunctionalTestCase;

use function key;

class QuotingTest extends DbalFunctionalTestCase
{
/**
Expand All @@ -29,4 +31,30 @@ public static function stringLiteralProvider(): iterable
'single-quote' => ["'"],
];
}

/**
* @dataProvider identifierProvider
*/
public function testQuoteIdentifier(string $identifier): void
{
$platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL(
'NULL AS ' . $platform->quoteIdentifier($identifier)
);

self::assertSame($identifier, key($this->connection->fetchAssociative($query)));
}

/**
* @return iterable<string,array{0:string}>
*/
public static function identifierProvider(): iterable
{
return [
'[' => ['['],
']' => [']'],
'"' => ['"'],
'`' => ['`'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,14 @@ public function testModifyLimitSubquerySimple(): void

public function testQuoteIdentifier(): void
{
self::assertEquals('[fo][o]', $this->platform->quoteIdentifier('fo]o'));
self::assertEquals('[fo]]o]', $this->platform->quoteIdentifier('fo]o'));
self::assertEquals('[test]', $this->platform->quoteIdentifier('test'));
self::assertEquals('[test].[test]', $this->platform->quoteIdentifier('test.test'));
}

public function testQuoteSingleIdentifier(): void
{
self::assertEquals('[fo][o]', $this->platform->quoteSingleIdentifier('fo]o'));
self::assertEquals('[fo]]o]', $this->platform->quoteSingleIdentifier('fo]o'));
self::assertEquals('[test]', $this->platform->quoteSingleIdentifier('test'));
self::assertEquals('[test.test]', $this->platform->quoteSingleIdentifier('test.test'));
}
Expand Down

0 comments on commit 8809142

Please sign in to comment.