Skip to content

Commit

Permalink
Fix bridges behavior broken in 2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Oct 10, 2024
1 parent c7f76e1 commit 8b77084
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Revision history for Kelp
[Changes]
- Middleware building is now done using Kelp::Middleware, making it easier to customize
- Kelp now uses a dynamic PSGI execution chain, allowing adding PSGI middlewares at route level
- Fixed trailing slash bridges not applying for deeper paths (broken in 2.18)

2.18 - 2024-10-08
[New Interface]
Expand Down
4 changes: 3 additions & 1 deletion lib/Kelp/Routes/Pattern.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ sub _build_regex
# - /test/ matches
# - /test/something matches
# - /testsomething does not match
$pattern .= '(?:/|$)';
# if the bridge is already followed by a trailing slash, it's not a
# concern
$pattern .= '(?:/|$)' unless $trailing_slash;
}
else {

Expand Down
22 changes: 22 additions & 0 deletions t/routes_match.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ my $r = Kelp::Routes->new;
is_deeply _d($r->match('/a/b/c'), 'to'), [{to => 'A::b'}, {to => 'A::d'}];
}

# Bridges - root
{
$r->clear;
$r->add('' => {to => 'a#b', bridge => 1});
$r->add('/' => {to => 'a#c', bridge => 1});

is_deeply _d($r->match('/'), 'to'), [{to => 'A::b'}, {to => 'A::c'}];
is_deeply _d($r->match('/test'), 'to'), [{to => 'A::b'}, {to => 'A::c'}];
}

# Bridges - trailing slashes
{
$r->clear;
$r->add('/test' => {to => 'a#b', bridge => 1});
$r->add('/test/' => {to => 'a#c', bridge => 1});

is_deeply _d($r->match('/test'), 'to'), [{to => 'A::b'}];
is_deeply _d($r->match('/test/'), 'to'), [{to => 'A::b'}, {to => 'A::c'}];
is_deeply _d($r->match('/test/more'), 'to'), [{to => 'A::b'}, {to => 'A::c'}];
is_deeply _d($r->match('/test/more/stuff'), 'to'), [{to => 'A::b'}, {to => 'A::c'}];
}

# Bridges - no longer url parts than defined
{
$r->clear;
Expand Down

0 comments on commit 8b77084

Please sign in to comment.