Skip to content

Commit

Permalink
#372 - Route segment filtering
Browse files Browse the repository at this point in the history
- Add 'slug' expression constraint
- If the target contains a contraint the target segment will be filtered acoordingly
  • Loading branch information
johanjanssens committed Jun 17, 2020
1 parent 0848293 commit 3598b6e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions code/site/components/com_pages/dispatcher/router/resolver/regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ protected function _initialize(KObjectConfig $config)
$config->append(array(
'routes' => array(),
'types' => [
'email' => '\S+@\S+',
'month' => '(0?[1-9]|1[012])',
'year' => '(19|20)\d{2}',
'digit' => '[0-9]++',
'email' => '\S+@\S+',
'month' => '(0?[1-9]|1[012])',
'year' => '(19|20)\d{2}',
'digit' => '[0-9]++',
'*digit' => '[0-9]+(,[0-9]+)*',
'alnum' => '[0-9A-Za-z]++',
'alnum' => '[0-9A-Za-z]++',
'*alnum' => '[0-9A-Za-z]+(,[0-9A-Za-z]+)*',
'alpha' => '[A-Za-z]++',
'alpha' => '[A-Za-z]++',
'*alpha' => '[A-Za-z]+(,[A-Za-z]+)*',
'*' => '.+?',
'**' => '.++',
'' => '[^/\.]++',
'slug' => '[0-9]++[-]++([0-9A-Za-z-]++)',
'*' => '.+?',
'**' => '.++',
'' => '[^/\.]++',
],
));

Expand Down Expand Up @@ -341,11 +342,19 @@ protected function _buildRoute($regex, ComPagesDispatcherRouterRouteInterface $r
if(isset($route->query[$param]))
{
if(is_array($route->query[$param])) {
$value= implode(',', $route->query[$param]);
$value = implode(',', $route->query[$param]);
} else {
$value = $route->query[$param];
}

if ($type && isset($this->_match_types[$type]))
{
$type = $this->_match_types[$type];

preg_match('/'.$type.'/', $value, $matches);
$value = $matches[1] ?? $value;
}

//Part is found, replace for param value
$regex = str_replace($block, $value, $regex);

Expand Down

0 comments on commit 3598b6e

Please sign in to comment.