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

Commit a22b33d

Browse files
committed
Merge pull request zendframework#458 from IvanGL/master
Fixed bug in quoteInto with $count parameter and question sign in $value
2 parents 0bfb328 + f608be8 commit a22b33d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

library/Zend/Db/Adapter/Abstract.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -930,13 +930,7 @@ public function quoteInto($text, $value, $type = null, $count = null)
930930
if ($count === null) {
931931
return str_replace('?', $this->quote($value, $type), $text);
932932
} else {
933-
while ($count > 0) {
934-
if (strpos($text, '?') !== false) {
935-
$text = substr_replace($text, $this->quote($value, $type), strpos($text, '?'), 1);
936-
}
937-
--$count;
938-
}
939-
return $text;
933+
return implode($this->quote($value, $type), explode('?', $text, $count + 1));
940934
}
941935
}
942936

tests/Zend/Db/Adapter/TestCommon.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,16 @@ public function testAdapterQuoteIntoCount()
12671267
'Incorrect quoteInto() result for count');
12681268
}
12691269

1270+
public function testAdapterQuoteIntoCountAndQuestionMark()
1271+
{
1272+
$string = 'foo = ? OR moo = ? OR boo = ?';
1273+
$param = 'What?';
1274+
$value = $this->_db->quoteInto($string, $param, null, 2);
1275+
$this->assertTrue(is_string($value));
1276+
$this->assertEquals("foo = 'What?' OR moo = 'What?' OR boo = ?", $value,
1277+
'Incorrect quoteInto() result for count and question mark in value');
1278+
}
1279+
12701280
public function testAdapterQuoteTypeInt()
12711281
{
12721282
foreach ($this->_numericDataTypes as $typeName => $type) {

0 commit comments

Comments
 (0)