Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit d4887a0

Browse files
committed
Change "new line" char on space char instead of blank char to preserve a very rare case with raw subquery with "new line" chars inside
1 parent 1396c59 commit d4887a0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

library/Zend/Db/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function _tableCols($correlationName, $cols, $afterCorrelationName = n
940940
$currentCorrelationName = $correlationName;
941941
if (is_string($col)) {
942942
// Check for a column matching "<column> AS <alias>" and extract the alias name
943-
$col = str_replace("\n",'',$col);
943+
$col = str_replace("\n",' ',$col);
944944
if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.+)$/i', $col, $m)) {
945945
$col = $m[1];
946946
$alias = $m[2];

tests/Zend/Db/Select/StaticTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,22 @@ public function testAssembleQueryWithSubqueryInSelectBlock() {
10231023
$select = $this->_db->select();
10241024
$select->from(array('t' => 'table1'), $columns);
10251025

1026-
$expected = 'SELECT (SELECT "st1"."col1", "st2"."col2" FROM "subTable1" AS "st1" INNER JOIN "subTable2" AS "st2" ON st1.fk_id=st2.fk_id) AS "subInSelect" FROM "table1" AS "t"';
1026+
$expected = 'SELECT (SELECT "st1"."col1", "st2"."col2" FROM "subTable1" AS "st1" INNER JOIN "subTable2" AS "st2" ON st1.fk_id=st2.fk_id) AS "subInSelect" FROM "table1" AS "t"';
10271027

10281028
$this->assertEquals($expected, $select->assemble(),
10291029
'Assembling query with subquery with join failed');
10301030
}
10311031

1032+
public function testAssembleQueryWithRawSubqueryInSelectBlock() {
1033+
$columns[] = '(SELECT *
1034+
FROM tb2) as subInSelect2';
1035+
$select = $this->_db->select();
1036+
$select->from(array('t' => 'table1'), $columns);
1037+
1038+
$expected = 'SELECT (SELECT * FROM tb2) AS "subInSelect2" FROM "table1" AS "t"';
1039+
1040+
$this->assertEquals($expected, $select->assemble(),
1041+
'Assembling query with raw subquery with "new line" char failed');
1042+
}
1043+
10321044
}

0 commit comments

Comments
 (0)