From 3bddcc412036cf62596ddc174ee80a288e79d999 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 11 Aug 2010 16:34:51 -0600 Subject: [PATCH] Throw exception on redirect() failure --- framework/Url/lib/Horde/Url.php | 7 +++++++ framework/Url/test/Horde/Url/RedirectTest.php | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 framework/Url/test/Horde/Url/RedirectTest.php diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 78cc1e8d0..66b1ef161 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -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 index 000000000..46037b22a --- /dev/null +++ b/framework/Url/test/Horde/Url/RedirectTest.php @@ -0,0 +1,22 @@ + + * @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) {} + } + +} -- 2.11.0