Skip to content

Commit

Permalink
#372 - Regex improvements
Browse files Browse the repository at this point in the history
- Add 'id' type
- Do not use a match group for 'slug' type
  • Loading branch information
johanjanssens committed Jun 18, 2020
1 parent 50a41c6 commit 01b7f8d
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected function _initialize(KObjectConfig $config)
'*alnum' => '[0-9A-Za-z]+(,[0-9A-Za-z]+)*',
'alpha' => '[A-Za-z]++',
'*alpha' => '[A-Za-z]+(,[A-Za-z]+)*',
'slug' => '[0-9]++[-]++([0-9A-Za-z-]++)',
'id' => '[0-9]++[-]++[0-9A-Za-z-]++',
'slug' => '[^0-9-][a-z-0-9]++',
'*' => '.+?',
'**' => '.++',
'' => '[^/\.]++',
Expand Down Expand Up @@ -351,8 +352,10 @@ protected function _buildRoute($regex, ComPagesDispatcherRouterRouteInterface $r
{
$type = $this->_match_types[$type];

preg_match('/'.$type.'/', $value, $matches);
$value = $matches[1] ?? $value;
//Get first capturing group if it exists, if not use full match
if(preg_match('/'.$type.'/', $value, $matches)) {
$value = $matches[0] ?? $value;
}
}

//Part is found, replace for param value
Expand Down

0 comments on commit 01b7f8d

Please sign in to comment.