]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
begin bookmark model class with URL validation method
authorChristian Weiske <cweiske@cweiske.de>
Tue, 3 May 2011 07:14:32 +0000 (09:14 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 3 May 2011 07:14:32 +0000 (09:14 +0200)
data/config.default.php
src/SemanticScuttle/Model/Bookmark.php [new file with mode: 0644]
src/SemanticScuttle/header.php
tests/Model/BookmarkTest.php [new file with mode: 0644]

index af79891e9bb7fb6be7e1145c0becad2cd92eadf2..b2c73070187be71e234bc6cf254462f48d3ac3f1 100644 (file)
@@ -462,6 +462,21 @@ $filetypes = array(
     'video'    => array('avi', 'mov', 'mp4', 'mpeg', 'mpg', 'wmv')
 );
 
+/**
+ * Link protocols that are allowed for newly added bookmarks.
+ * This prevents i.e. adding javascript: links.
+ *
+ * @link http://en.wikipedia.org/wiki/URI_scheme
+ *
+ * @var array
+ */
+$allowedProtocols = array(
+    'ftp', 'ftps',
+    'http', 'https',
+    'mailto', 'nntp',
+    'xmpp'
+);
+
 /**
  * Enable the "common bookmark description" functionality
  *
diff --git a/src/SemanticScuttle/Model/Bookmark.php b/src/SemanticScuttle/Model/Bookmark.php
new file mode 100644 (file)
index 0000000..2cbe38d
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Bookmark model class, keeping the data of a single bookmark.
+ * It will slowly replace the old array style format.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class SemanticScuttle_Model_Bookmark
+{
+    public static function isValidUrl($url)
+    {
+        $scheme = parse_url($url, PHP_URL_SCHEME);
+        if (array_search($scheme, $GLOBALS['allowedProtocols']) === false) {
+            return false;
+        }
+        return true;
+    }
+
+}
+
+
+?>
\ No newline at end of file
index 75e52041f3fc2a09c5ded23e0966f06306f5d0df..d81212439b54eede58c43f4178cdbddf31de8f3e 100644 (file)
@@ -82,6 +82,7 @@ require_once 'SemanticScuttle/Service.php';
 require_once 'SemanticScuttle/DbService.php';
 require_once 'SemanticScuttle/Service/Factory.php';
 require_once 'SemanticScuttle/functions.php';
+require_once 'SemanticScuttle/Model/Bookmark.php';
 require_once 'SemanticScuttle/Model/UserArray.php';
 
 if (count($GLOBALS['serviceoverrides']) > 0
diff --git a/tests/Model/BookmarkTest.php b/tests/Model/BookmarkTest.php
new file mode 100644 (file)
index 0000000..9f55143
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Unit tests for the SemanticScuttle Bookmark model
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class Model_BookmarkTest extends TestBase
+{
+    public function testIsValidUrlValid()
+    {
+        $this->assertTrue(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'http://example.org/foo/bar?baz=foorina'
+            )
+        );
+        $this->assertTrue(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'https://example.org/'
+            )
+        );
+        $this->assertTrue(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'ftp://user:pass@example.org/'
+            )
+        );
+        $this->assertTrue(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'mailto:cweiske@example.org'
+            )
+        );
+    }
+
+    public function testIsValidUrlInvalid()
+    {
+        $this->assertFalse(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'javascript:alert("foo")'
+            )
+        );
+        $this->assertFalse(
+            SemanticScuttle_Model_Bookmark::isValidUrl(
+                'foo://example.org/foo/bar'
+            )
+        );
+    }
+
+}
+
+?>
\ No newline at end of file