Skip to content

Commit

Permalink
zendframework#7222 processJoins quote identifier error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevus committed Feb 27, 2015
1 parent 5e9408f commit 73157a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 1 addition & 4 deletions library/Zend/Db/Adapter/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = array(
return $identifier;
}

$safeRegex = '';
$safeWordsInt = array('*' => true, ' ' => true, '.' => true, 'as' => true);

foreach ($safeWords as $sWord) {
$safeWordsInt[strtolower($sWord)] = true;

$safeRegex .= '|' . preg_quote($sWord);
}

$parts = preg_split(
'/([\.\s]' . $safeRegex . ')/i',
'/([^0-9,a-z,A-Z$_:])/i',
$identifier,
-1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
Expand Down
14 changes: 14 additions & 0 deletions tests/ZendTest/Db/Sql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,19 @@ public function providerData()
$sqlStr51 = 'SELECT "foo".* FROM "foo" WHERE ("bar" IS NULL OR 1=1)';
$internalTests51 = array();

/**
* @author Andrzej Lewandowski
* @link https://github.com/zendframework/zf2/issues/7222
*/
$select52 = new Select;
$select52->from('foo')->join('zac', '(catalog_category_website.category_id = catalog_category.category_id)');
$sqlPrep52 = // same
$sqlStr52 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON ("catalog_category_website"."category_id" = "catalog_category"."category_id")';
$internalTests52 = array(
'processSelect' => array(array(array('"foo".*'), array('"zac".*')), '"foo"'),
'processJoins' => array(array(array('INNER', '"zac"', '("catalog_category_website"."category_id" = "catalog_category"."category_id")')))
);

/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
Expand Down Expand Up @@ -1354,6 +1367,7 @@ public function providerData()
array($select49, $sqlPrep49, array(), $sqlStr49, $internalTests49),
array($select50, $sqlPrep50, array(), $sqlStr50, $internalTests50),
array($select51, $sqlPrep51, array(), $sqlStr51, $internalTests51),
array($select52, $sqlPrep52, array(), $sqlStr52, $internalTests52),
);
}
}

0 comments on commit 73157a1

Please sign in to comment.