Skip to content

Commit

Permalink
fixed path generation bug in Mojolicious::Routes::Pattern (closes #456)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 21, 2013
1 parent e4874cb commit 1d4a435
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Improved portability of Mojo::Asset::File tests.
- Improved documentation.
- Improved tests. (jberger, sri)
- Fixed path generation bug in Mojolicious::Routes::Pattern. (jberger)
- Fixed small domain detection bug in Mojo::UserAgent::CookieJar.
(dione, sri)
- Fixed comment lines in Mojo::Template to cover the whole line.
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -36,8 +36,10 @@ sub render {
my $format = ($values ||= {})->{format};
$values = {%{$self->defaults}, %$values};

my $string = '';
my $optional = 1;
# Placeholders can only be optional without a format
my $optional = !$format;

my $string = '';
for my $token (reverse @{$self->tree}) {
my $op = $token->[0];
my $rendered = '';
Expand Down
3 changes: 3 additions & 0 deletions t/mojolicious/routes.t
Expand Up @@ -248,6 +248,7 @@ $m->match($r, $c);
is $m->stack->[0]{foo}, 11, 'right value';
is @{$m->stack}, 1, 'right number of elements';
is $m->path_for, '/alternatives', 'right path';
is $m->path_for(format => 'txt'), '/alternatives/11.txt', 'right path';
$m = Mojolicious::Routes::Match->new(GET => '/alternatives/0');
$m->match($r, $c);
is $m->stack->[0]{foo}, 0, 'right value';
Expand All @@ -273,6 +274,8 @@ $m = Mojolicious::Routes::Match->new(GET => '/alternatives/00');
$m->match($r, $c);
is @{$m->stack}, 0, 'right number of elements';
is $m->path_for('alternativesfoo'), '/alternatives', 'right path';
is $m->path_for('alternativesfoo', format => 'txt'), '/alternatives/11.txt',
'right path';

# Alternatives without default
$m = Mojolicious::Routes::Match->new(GET => '/alternatives2');
Expand Down

0 comments on commit 1d4a435

Please sign in to comment.