Просмотр исходного кода

Merge pull request #458 from IvanGL/master

Fixed bug in quoteInto with $count parameter and question sign in $value
Frank Brückner 11 лет назад
Родитель
Сommit
a22b33ded6
2 измененных файлов с 11 добавлено и 7 удалено
  1. 1 7
      library/Zend/Db/Adapter/Abstract.php
  2. 10 0
      tests/Zend/Db/Adapter/TestCommon.php

+ 1 - 7
library/Zend/Db/Adapter/Abstract.php

@@ -930,13 +930,7 @@ abstract class Zend_Db_Adapter_Abstract
         if ($count === null) {
             return str_replace('?', $this->quote($value, $type), $text);
         } else {
-            while ($count > 0) {
-                if (strpos($text, '?') !== false) {
-                    $text = substr_replace($text, $this->quote($value, $type), strpos($text, '?'), 1);
-                }
-                --$count;
-            }
-            return $text;
+            return implode($this->quote($value, $type), explode('?', $text, $count + 1));
         }
     }
 

+ 10 - 0
tests/Zend/Db/Adapter/TestCommon.php

@@ -1267,6 +1267,16 @@ abstract class Zend_Db_Adapter_TestCommon extends Zend_Db_TestSetup
             'Incorrect quoteInto() result for count');
     }
 
+    public function testAdapterQuoteIntoCountAndQuestionMark()
+    {
+        $string = 'foo = ? OR moo = ? OR boo = ?';
+        $param = 'What?';
+        $value = $this->_db->quoteInto($string, $param, null, 2);
+        $this->assertTrue(is_string($value));
+        $this->assertEquals("foo = 'What?' OR moo = 'What?' OR boo = ?", $value,
+            'Incorrect quoteInto() result for count and question mark in value');
+    }
+
     public function testAdapterQuoteTypeInt()
     {
         foreach ($this->_numericDataTypes as $typeName => $type) {