Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3586' into develop
Browse files Browse the repository at this point in the history
Close #3586
Fixes #2563
  • Loading branch information
weierophinney committed Jan 29, 2013
2 parents 96e3466 + f262172 commit a13c2b3
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 61 deletions.
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/IbmDb2.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = array(
}
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = array(
{
// regex taken from @link http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
$parts = preg_split('#([^0-9,a-z,A-Z$_])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}
switch ($part) {
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/Oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = array(
return $identifier;
}
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}
switch ($part) {
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/Postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public function getIdentifierSeparator()
public function quoteIdentifierInFragment($identifier, array $safeWords = array())
{
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}
switch ($part) {
Expand Down
7 changes: 5 additions & 2 deletions library/Zend/Db/Adapter/Platform/Sql92.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ public function getIdentifierSeparator()
public function quoteIdentifierInFragment($identifier, array $safeWords = array())
{
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/SqlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public function getIdentifierSeparator()
public function quoteIdentifierInFragment($identifier, array $safeWords = array())
{
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}
switch ($part) {
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Platform/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ public function getIdentifierSeparator()
public function quoteIdentifierInFragment($identifier, array $safeWords = array())
{
$parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if ($safeWords) {
$safeWords = array_flip($safeWords);
$safeWords = array_change_key_case($safeWords, CASE_LOWER);
}
foreach ($parts as $i => $part) {
if ($safeWords && in_array($part, $safeWords)) {
if ($safeWords && isset($safeWords[strtolower($part)])) {
continue;
}
switch ($part) {
Expand Down
15 changes: 7 additions & 8 deletions tests/ZendTest/Db/Adapter/Platform/IbmDb2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ public function testQuoteIdentifierInFragment()
$platform = new IbmDb2(array('quote_identifiers' => false));
$this->assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\IbmDb2::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));
}

// case insensitive safe words
$this->assertEquals(
'("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
14 changes: 7 additions & 7 deletions tests/ZendTest/Db/Adapter/Platform/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ public function testQuoteIdentifierInFragment()
$this->assertEquals('`foo`.`bar`', $this->platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('`foo` as `bar`', $this->platform->quoteIdentifierInFragment('foo as bar'));
$this->assertEquals('`$TableName`.`bar`', $this->platform->quoteIdentifierInFragment('$TableName.bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\Mysql::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('(`foo`.`bar` = `boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));

// case insensitive safe words
$this->assertEquals(
'(`foo`.`bar` = `boo`.`baz`) AND (`foo`.`baz` = `boo`.`baz`)',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
15 changes: 7 additions & 8 deletions tests/ZendTest/Db/Adapter/Platform/OracleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ public function testQuoteIdentifierInFragment()
$platform = new Oracle(array('quote_identifiers' => false));
$this->assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\Oracle::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));
}

// case insensitive safe words
$this->assertEquals(
'("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
14 changes: 7 additions & 7 deletions tests/ZendTest/Db/Adapter/Platform/PostgresqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public function testQuoteIdentifierInFragment()
{
$this->assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\Postgresql::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));

// case insensitive safe words
$this->assertEquals(
'("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
15 changes: 7 additions & 8 deletions tests/ZendTest/Db/Adapter/Platform/Sql92Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ public function testQuoteIdentifierInFragment()
{
$this->assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\Sql92::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));
}

// case insensitive safe words
$this->assertEquals(
'("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
14 changes: 7 additions & 7 deletions tests/ZendTest/Db/Adapter/Platform/SqlServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public function testQuoteIdentifierInFragment()
{
$this->assertEquals('[foo].[bar]', $this->platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('[foo] as [bar]', $this->platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\SqlServer::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('([foo].[bar] = [boo].[baz])', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));

// case insensitive safe words
$this->assertEquals(
'([foo].[bar] = [boo].[baz]) AND ([foo].[baz] = [boo].[baz])',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}
15 changes: 7 additions & 8 deletions tests/ZendTest/Db/Adapter/Platform/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ public function testQuoteIdentifierInFragment()
{
$this->assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar'));
$this->assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar'));
}

/**
* @group ZF2-386
* @covers Zend\Db\Adapter\Platform\Postgresql::quoteIdentifierInFragment
*/
public function testQuoteIdentifierInFragmentIgnoresSingleCharSafeWords()
{
// single char words
$this->assertEquals('("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', array('(', ')', '=')));
}

// case insensitive safe words
$this->assertEquals(
'("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")',
$this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz) AND (foo.baz = boo.baz)', array('(', ')', '=', 'and'))
);
}
}

0 comments on commit a13c2b3

Please sign in to comment.