Skip to content

Commit

Permalink
fixed bug in Mojolicious::Routes::Match where placeholder values got …
Browse files Browse the repository at this point in the history
…merged too early (closes #667)
  • Loading branch information
kraih committed Aug 11, 2014
1 parent bffa369 commit f5b6b08
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,8 @@
- Added support for nested helpers.
- Added get_helper method to Mojolicious::Renderer.
- Added n function to ojo.
- Fixed bug in Mojolicious::Routes::Match where placeholder values got
merged too early.

5.26 2014-08-09
- Improved WebSocket performance.
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious/Routes/Match.pm
Expand Up @@ -44,8 +44,6 @@ sub _match {
my $detect = (my $endpoint = $r->is_endpoint) && !$partial;
return unless my $captures = $r->pattern->match_partial(\$path, $detect);
local $options->{path} = $path;
@{$self->{captures} ||= {}}{keys %$captures} = values %$captures;
$captures = $self->{captures};
# Method
my $methods = $r->via;
Expand All @@ -63,6 +61,10 @@ sub _match {
# WebSocket
return if $r->is_websocket && !$options->{websocket};
# Merge after everything matched
@{$self->{captures} ||= {}}{keys %$captures} = values %$captures;
$captures = $self->{captures};
# Partial
my $empty = !length $path || $path eq '/';
if ($partial) {
Expand Down
17 changes: 17 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -197,6 +197,12 @@ $r->route('/missing/too/*', '' => ['test'])
# /partial/*
$r->route('/partial')->detour('foo#bar');

# GET /similar/*
# POST /similar/too
my $similar = $r->bridge('/similar');
$similar->route('/:something')->via('GET')->to('similar#get');
$similar->route('/too')->via('POST')->to('similar#post');

# Cached lookup
my $fast = $r->route('/fast');
is $r->find('fast'), $fast, 'fast route found';
Expand Down Expand Up @@ -863,4 +869,15 @@ is_deeply $m->stack,
[{controller => 'foo', action => 'bar', 'path' => '.test'}],
'right structure';

# Similar routes with placeholders
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/similar/too'});
is_deeply $m->stack,
[{}, {controller => 'similar', action => 'get', 'something' => 'too'}],
'right structure';
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'POST', path => '/similar/too'});
is_deeply $m->stack, [{}, {controller => 'similar', action => 'post'}],
'right structure';

done_testing();

0 comments on commit f5b6b08

Please sign in to comment.