Skip to content

Commit

Permalink
Failing test to identify string literal quoting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 24, 2018
1 parent 1b1adc2 commit 55b409b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
10 changes: 0 additions & 10 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1175,14 +1175,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);
}
}
10 changes: 0 additions & 10 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,16 +1199,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' => ["'"],
];
}
}

0 comments on commit 55b409b

Please sign in to comment.