PerlDancer/Dancer2 — pull request #817 by xsawyerx (2014-12-23 13:42:54+00:00)
Title: Consistent prefixes: variables and leading forward slashes:

I couldn't break this down into multiple commits so instead a
single commit which fixes two issues. They are both tricky to
grasp and one might introduce breakage (while reducing breakage,
I guess), so they're important to understand.

The first relates to allowing variables in prefixes with a single
path request. If your route is simply '/', variables in the prefix
are simply ignored:

prefix '/:board' => sub {
get '/' => sub {...}
};

Now the actual route registered is '/:board/', literally. That
means that it won't accept variables but only '/:board/'.

The second issue is accepting anything that does not start with
a leading forward slash. This would be an error:

get '' => sub {...}; # breaks

If you have a prefix and you want to still grab the basic path
without the ending slash it would fail:

prefix '/:board' => sub {
get '' => sub {...}; # breaks
};

This is now fixed too.

One thing to research and perhaps write a test for is the behavior
using path() or path_info(). path() is defined by
path_info() || '/', which might be a problem.

Another issue to recognize is that if someone had the following
code and we don't cover for it, they will receive a 404:

prefix '/:board' => sub {
get '/' => sub {
# expecting to grab both /foo/ and /foo
};
};

This, if successful, closes GH #558 and possibly GH #793.