Skip to content

Commit

Permalink
fixed url_for bug where deeply nested WebSocket routes would not work…
Browse files Browse the repository at this point in the history
… correctly
  • Loading branch information
kraih committed Sep 26, 2014
1 parent eea6404 commit 3878d57
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -5,6 +5,8 @@
- Improved performance of next, next_sibling, previous and previous_sibling
methods in Mojo::DOM significantly.
- Improved Mojo::Cache to allow caching to be disabled. (mvgrimes, sri)
- Fixed url_for bug where deeply nested WebSocket routes would not work
correctly.

5.44 2014-09-23
- Fixed bug in Mojolicious::Renderer that prevented proxy objects from being
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Route.pm
Expand Up @@ -74,7 +74,7 @@ sub has_websocket {
my $self = shift;
return 1 if $self->is_websocket;
return undef unless my $parent = $self->parent;
return $parent->is_websocket;
return $parent->has_websocket;
}

sub is_endpoint { $_[0]->inline ? undef : !@{$_[0]->children} }
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/websocket.t
Expand Up @@ -382,7 +382,7 @@ $ua->websocket(
);
Mojo::IOLoop->start;
ok $finished, 'transaction is finished';
ok !$ws, 'no websocket';
ok !$ws, 'not a websocket';
is $code, 500, 'right status';
is $msg, 'Internal Server Error', 'right message';

Expand All @@ -398,7 +398,7 @@ $ua->websocket(
}
);
Mojo::IOLoop->start;
ok !$ws, 'no websocket';
ok !$ws, 'not a websocket';
is $code, 403, 'right status';
is $msg, "i'm a teapot", 'right message';

Expand Down
15 changes: 15 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -186,6 +186,10 @@ is $second->render('', {}), '/second', 'right result';
$target->add_child($first)->add_child($second);
is $second->render('', {}), '/target/second', 'right result';

# /websocket
$r->websocket('/websocket' => {controller => 'ws'})->route('/')
->to(action => 'just')->route->to(works => 1);

# /slash
$r->route('/slash')->to(controller => 'just')->route('/')
->to(action => 'slash');
Expand Down Expand Up @@ -828,13 +832,24 @@ $m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/target/third'});
is_deeply $m->stack, [], 'empty stack';

# WebSocket
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/websocket'});
is_deeply $m->stack, [], 'empty stack';
$m->match($c => {method => 'GET', path => '/websocket', websocket => 1});
is_deeply $m->stack, [{controller => 'ws', action => 'just', works => 1}],
'right structure';
is $m->path_for->{path}, '/websocket', 'right path';
ok $m->path_for->{websocket}, 'is a websocket';

# Just a slash with a format after a path
$m = Mojolicious::Routes::Match->new(root => $r);
$m->match($c => {method => 'GET', path => '/slash.txt'});
is_deeply $m->stack,
[{controller => 'just', action => 'slash', format => 'txt'}],
'right structure';
is $m->path_for->{path}, '/slash', 'right path';
ok !$m->path_for->{websocket}, 'not a websocket';
is $m->path_for(format => 'html')->{path}, '/slash.html', 'right path';

# Nameless placeholder
Expand Down

0 comments on commit 3878d57

Please sign in to comment.