From 0c9c0e44b4df572ee4a9b0af03aa0afb1723561c Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 3 Feb 2007 02:32:42 +0000 Subject: [PATCH] Adding fix for #1989 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4423 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index c261de8d5..38d64a115 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -61,6 +61,12 @@ class Router extends Overloadable { * @var boolean */ var $__parseExtensions = false; +/** + * Array of valid extensions to parse from a url + * + * @var boolean + */ + var $__validExtensions = array(); /** * 'Constant' regular expression definitions for named route elements * @@ -251,9 +257,22 @@ class Router extends Overloadable { if (strpos($url, '?') !== false) { $url = substr($url, 0, strpos($url, '?')); } - if ($_this->__parseExtensions && preg_match('/\.[0-9a-zA-Z]*$/', $url, $ext) == 1) { - $ext = substr($ext[0], 1); - $url = substr($url, 0, strpos($url, '.' . $ext)); + + if ($_this->__parseExtensions) { + if(preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) == 1) { + $match = substr($match[0], 1); + if(is_null($_this->__validExtensions)) { + $url = substr($url, 0, strpos($url, '.' . $match)); + $ext = $match; + } else { + foreach($_this->__validExtensions AS $name) { + if(strcasecmp($name, $match) === 0) { + $url = substr($url, 0, strpos($url, '.' . $name)); + $ext = $match; + } + } + } + } } foreach($_this->routes as $route) { @@ -677,11 +696,16 @@ class Router extends Overloadable { * automatically switch to alternate layouts and templates, and load helpers * corresponding to the given content, i.e. RssHelper. * + * An array of valid extension can be passed to this method. $extensions = array('rss', 'xml') + * If null is passed anything after a . in the url will be considered an extension + * + * @param mixed $extensions * @return void */ - function parseExtensions() { + function parseExtensions($extensions = null) { $_this =& Router::getInstance(); $_this->__parseExtensions = true; + $_this->__validExtensions = $extensions; } }