Skip to content

Commit

Permalink
fix url_for bug where routes with custom names would not match in the…
Browse files Browse the repository at this point in the history
… same order as routes with automatically generated names (closes #920)
  • Loading branch information
kraih committed Feb 26, 2016
1 parent 5ae4a30 commit ae4609a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -4,6 +4,8 @@
- Improved check_box and radio_button helpers with support for "on" default
values.
- Improved val method in Mojo::DOM with support for "on" default values.
- Fixed url_for bug where routes with custom names would not match in the same
order as routes with automatically generated names.
- Fixed Windows bug in "util.t".

6.48 2016-02-24
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -210,15 +210,15 @@ sub _generate_route {
sub _index {
my $self = shift;

my %index;
my (%auto, %custom);
my @children = (@{$self->children});
while (my $child = shift @children) {
if ($child->has_custom_name) { $index{$child->name} = $child }
else { $index{$child->name} ||= $child }
if ($child->has_custom_name) { $custom{$child->name} ||= $child }
else { $auto{$child->name} ||= $child }
push @children, @{$child->children};
}

return \%index;
return {%auto, %custom};
}

1;
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/routes.t
Expand Up @@ -10,7 +10,7 @@ my $r = Mojolicious::Routes->new;
$r->route('/clean')->to(clean => 1)->name('very_clean');

# /clean/too
$r->route('/clean/too')->to(something => 1);
$r->route('/clean/too')->to(something => 1)->name('very_clean');

# /0
$r->route('0')->to(null => 1);
Expand Down

0 comments on commit ae4609a

Please sign in to comment.