Skip to content
Snippets Groups Projects
Commit 1ffe6a39 authored by Peter Rotich's avatar Peter Rotich
Browse files

Fix bug where dispatcher would corrupt matched parameters if they have the

same value.
parent ca7e005d
No related branches found
No related tags found
No related merge requests found
......@@ -100,9 +100,11 @@ class UrlMatcher {
}
function dispatch($url, $prev_args=null) {
# Remove named values from the match array
$this->matches = array_flip(array_intersect(
array_flip($this->matches), range(0,31)));
$f = array_filter(array_keys($this->matches), 'is_numeric');
$this->matches = array_intersect_key($this->matches, array_flip($f));
if (@get_class($this->func) == "Dispatcher") {
# Trim the leading match off the $url and call the
# sub-dispatcher. This will be the case for lines in the URL
......@@ -116,29 +118,31 @@ class UrlMatcher {
substr($url, strlen($this->matches[0])),
array_merge(($prev_args) ? $prev_args : array(),
array_slice($this->matches, 1)));
} else {
# Drop the first item of the matches array (which is the whole
# matched url). Then merge in any initial arguments.
unset($this->matches[0]);
# Prepend received arguments (from a parent Dispatcher). This is
# different from the static args, which are postpended
if (is_array($prev_args))
$args = array_merge($prev_args, $this->matches);
else $args = $this->matches;
# Add in static args specified in the constructor
$args = array_merge($args, $this->args);
# Apply the $prefix given
list($class, $func) = $this->apply_prefix();
if ($class) {
# Create instance of the class, which is the first item,
# then call the method which is the second item
$func = array(new $class, $func);
}
if (!is_callable($func))
Http::response(500,
'Dispatcher compile error. Function not callable');
return call_user_func_array($func, $args);
}
# Drop the first item of the matches array (which is the whole
# matched url). Then merge in any initial arguments.
unset($this->matches[0]);
# Prepend received arguments (from a parent Dispatcher). This is
# different from the static args, which are postpended
if (is_array($prev_args))
$args = array_merge($prev_args, $this->matches);
else $args = $this->matches;
# Add in static args specified in the constructor
$args = array_merge($args, $this->args);
# Apply the $prefix given
list($class, $func) = $this->apply_prefix();
if ($class) {
# Create instance of the class, which is the first item,
# then call the method which is the second item
$func = array(new $class, $func);
}
if (!is_callable($func))
Http::response(500, 'Dispatcher compile error. Function not callable');
return call_user_func_array($func, $args);
}
/**
* For the $prefix recieved by the constuctor, prepend it to the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment