Throw exception on redirect() failure
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 11 Aug 2010 22:34:51 +0000 (16:34 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 11 Aug 2010 22:40:31 +0000 (16:40 -0600)
framework/Url/lib/Horde/Url.php
framework/Url/test/Horde/Url/RedirectTest.php [new file with mode: 0644]

index 78cc1e8..66b1ef1 100644 (file)
@@ -312,9 +312,16 @@ class Horde_Url
 
     /**
      * Sends a redirect request to the browser to the URL in this object.
+     *
+     * @throws Horde_Url_Exception
      */
     public function redirect()
     {
+        $url = strval($this->setRaw(true));
+        if (!strlen($url)) {
+            throw new Horde_Url_Exception('Redirect failed: URL is empty.');
+        }
+
         header('Location: ' . strval($this->setRaw(true)));
         exit;
     }
diff --git a/framework/Url/test/Horde/Url/RedirectTest.php b/framework/Url/test/Horde/Url/RedirectTest.php
new file mode 100644 (file)
index 0000000..46037b2
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/**
+ * @author     Michael Slusarz <slusarz@horde.org>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @category   Horde
+ * @package    Url
+ * @subpackage UnitTests
+ */
+
+class Horde_Url_RedirectTest extends PHPUnit_Framework_TestCase
+{
+    public function testEmptyRedirect()
+    {
+        $url = new Horde_Url('');
+
+        try {
+            $url->redirect();
+            $this->fail();
+        } catch (Horde_Url_Exception $e) {}
+    }
+
+}