]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
do not generate invalid SQL when called with a not-so valid array
authorChristian Weiske <cweiske@cweiske.de>
Fri, 25 Mar 2011 07:00:32 +0000 (08:00 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 25 Mar 2011 07:00:32 +0000 (08:00 +0100)
src/SemanticScuttle/Service/Bookmark2Tag.php
tests/Bookmark2TagTest.php

index 1dc0ffe4164e0ec890dc2e0eb2aa97e1b7415b86..a10cb612e14ecac74cbb0ebcc48abe4be92e9e2f 100644 (file)
@@ -571,8 +571,10 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
         } else if (is_array($user)) {
             $query .= ' (1 = 0';  //tricks
             foreach ($user as $u) {
-                $query .= ' OR B.uId = ' . $this->db->sql_escape($u)
-                    . ' AND B.bId = T.bId';
+                if (is_numeric($u)) {
+                    $query .= ' OR B.uId = ' . $this->db->sql_escape($u)
+                        . ' AND B.bId = T.bId';
+                }
             }
             $query .= ' )' . $privacy;
         } else {
index ffd83c38476ed6313b4f9712fa48c4359dfe1ce6..fff4222c6ea43bf9ed56bbfe96fef5711c30aa92 100644 (file)
@@ -426,6 +426,23 @@ class Bookmark2TagTest extends TestBase
 
 
 
+    /**
+     * This may happen when the method is called with a problematic user array.
+     * In that case we may not generate invalid SQL or so.
+     *
+     * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+     */
+    public function testGetPopularTagsUserArrayWithNull()
+    {
+        $user1 = $this->addUser();
+        $this->addTagBookmark($user1, array('one'));
+
+        $arTags = $this->b2ts->getPopularTags(array(null));
+        $this->assertEquals(0, count($arTags));
+    }
+
+
+
     /**
      * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
      */