Skip to content

Commit

Permalink
Ensure megasplat keeps empty trailing fields
Browse files Browse the repository at this point in the history
The string that a megasplat matched is split on '/'. Without setting an
LIMIT for the split, empty trailing values get stripped. That is;
for the route '/foo/**', the paths '/foo/bar' and '/foo/bar/'
were both giving the splat as [ 'bar' ].

Or, if there were further trailing slashes in the path:
'/foo/bar///a'  gave  ['bar','','','a'] but
'/foo/bar///'   gave  ['bar'].   How's that for inconsistent.

Instead, this commit adds a (negative) limit to the split on megasplat
values so that empty trailing values are kept, which allows you to join
the arrayref of values together and get the original path again. The
above examples are:
'/foo/bar/'     giving ['bar','']
'/foo/bar///a'  giving ['bar','','','a']  #as before
'/foo/bar///'   giving ['bar','','']

This is a subtle change in behaviour, which _may_ cause some Dancers
issues if they are not aware of the change.

Closes #1155.
  • Loading branch information
veryrusty committed Apr 13, 2016
1 parent bb62eca commit 89a1a07
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Dancer2/Core/Route.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ sub match {

# megasplat values are split on '/'
if ($token_or_splat[$i] eq 'megasplat') {
$values[$i] = [ split '/' => $values[$i] || '' ];
$values[$i] = [
defined $values[$i] ? split( '/' , $values[$i], -1 ) : ''
];
}
push @splat, $values[$i];
}
Expand Down

0 comments on commit 89a1a07

Please sign in to comment.