]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
do not add bookmarks with an invalid URL
authorChristian Weiske <cweiske@cweiske.de>
Tue, 3 May 2011 17:10:12 +0000 (19:10 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 3 May 2011 17:10:12 +0000 (19:10 +0200)
src/SemanticScuttle/Service/Bookmark.php
tests/BookmarkTest.php

index a30ad5f6a0f443afab43683548dd1a7a2f8eb80a..919ca7a8a3c304bd3e2f81c3c15869d05546d4ab 100644 (file)
@@ -435,6 +435,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
     /**
      * Adds a bookmark to the database.
      *
+     * Security checks are being made here, but no error reasons will be
+     * returned. It is the responsibility of the code that calls
+     * addBookmark() to verify the data.
+     *
      * @param string  $address     Full URL of the bookmark
      * @param string  $title       Bookmark title
      * @param string  $description Long bookmark description
@@ -453,7 +457,8 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
      * @param boolean $fromImport  True when the bookmark is from an import.
      * @param integer $sId         ID of user who creates the bookmark.
      *
-     * @return integer Bookmark ID
+     * @return mixed Integer bookmark ID if saving succeeded, false in
+     *               case of an error. Error reasons are not returned.
      */
     public function addBookmark(
         $address, $title, $description, $privateNote, $status, $tags,
@@ -466,6 +471,9 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
         }
 
         $address = $this->normalize($address);
+        if (!SemanticScuttle_Model_Bookmark::isValidUrl($address)) {
+            return false;
+        }
 
         /*
          * Note that if date is NULL, then it's added with a date and
index e7ce48817143b80d21ff60e8704994a78f5712dd..7533f3a3a47bcb03cb8d79d02de8af0e9651d645 100644 (file)
@@ -65,7 +65,16 @@ class BookmarkTest extends TestBase
         $this->assertEquals('myShortName', $bm['bShort']);
     }
 
-    public function testHardCharactersInBookmarks()
+    public function testAddBookmarkInvalidUrl()
+    {
+        $retval = $this->bs->addBookmark(
+            'javascript:alert(123)', 'title', 'desc', 'priv',
+            0, array()
+        );
+        $this->assertFalse($retval, 'Bookmark with invalid URL was accepted');
+    }
+
+    public function testAddBookmarkWithSpecialCharacters()
     {
         $bs = $this->bs;
         $title = "title&é\"'(-è_çà)=";