Created
October 13, 2012 23:23
-
-
Save zeelot/3886578 to your computer and use it in GitHub Desktop.
trying to fix #4113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/classes/Kohana/Route.php b/classes/Kohana/Route.php | |
index fdd2e1b..d8e33fe 100644 | |
--- a/classes/Kohana/Route.php | |
+++ b/classes/Kohana/Route.php | |
@@ -531,8 +531,12 @@ class Kohana_Route { | |
return rtrim($params['host'], '/').'/'.$uri; | |
} | |
+ // Keep track of whether an optional param was replaced | |
+ $provided_optional = FALSE; | |
+ | |
while (preg_match('#\([^()]++\)#', $uri, $match)) | |
{ | |
+ | |
// Search for the matched value | |
$search = $match[0]; | |
@@ -545,9 +549,27 @@ class Kohana_Route { | |
if (isset($params[$param])) | |
{ | |
+ // Future optional params should be required | |
+ $provided_optional = TRUE; | |
+ | |
// Replace the key with the parameter value | |
$replace = str_replace($key, $params[$param], $replace); | |
} | |
+ elseif ($provided_optional) | |
+ { | |
+ // Look for a default | |
+ if (isset($this->_defaults[$param])) | |
+ { | |
+ $replace = str_replace($key, $this->_defaults[$param], $replace); | |
+ } | |
+ else | |
+ { | |
+ // Ungrouped parameters are required | |
+ throw new Kohana_Exception('Required route parameter not passed: :param', array( | |
+ ':param' => $param, | |
+ )); | |
+ } | |
+ } | |
else | |
{ | |
// This group has missing parameters | |
@@ -577,7 +599,7 @@ class Kohana_Route { | |
throw new Kohana_Exception('Required route parameter not passed: :param', array( | |
':param' => $param, | |
)); | |
- } | |
+ } | |
} | |
$uri = str_replace($key, $params[$param], $uri); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment