Skip to content

Commit

Permalink
fixed small route rendering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 22, 2011
1 parent 0c45a0a commit 76bc38c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Made tag helper a little smarter.
- Made camelize a little smarter.
- Improved documentation.
- Fixed small route rendering bug.

1.86 2011-08-21 00:00:00
- Deprecated camel case command modules and lowercased all the
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -83,9 +83,8 @@ sub render {
$rendered = $values->{$name};
$rendered = '' unless defined $rendered;
my $default = $self->defaults->{$name};
$default = '' unless defined $default;
$optional = 0 unless $default eq $rendered;
$rendered = '' if $optional && $default eq $rendered;
if (!defined $default || ($default ne $rendered)) { $optional = 0 }
elsif ($optional) { $rendered = '' }
}

$string = "$rendered$string";
Expand Down
5 changes: 3 additions & 2 deletions t/mojolicious/routes.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use Test::More tests => 339;
use Test::More tests => 340;

# "They're not very heavy, but you don't hear me not complaining."
use_ok 'Mojolicious::Routes';
Expand Down Expand Up @@ -250,7 +250,7 @@ $m = Mojolicious::Routes::Match->new(get => '/alternatives2/tset')->match($r);
is @{$m->stack}, 0, 'right number of elements';
$m = Mojolicious::Routes::Match->new(get => '/alternatives2/00')->match($r);
is @{$m->stack}, 0, 'right number of elements';
is $m->path_for('alternatives2foo'), '/alternatives2', 'right path';
is $m->path_for('alternatives2foo'), '/alternatives2/', 'right path';
is $m->path_for('alternatives2foo', foo => 0), '/alternatives2/0',
'right path';

Expand Down Expand Up @@ -422,6 +422,7 @@ is $m->stack->[0]->{controller}, 'wild', 'right value';
is $m->stack->[0]->{action}, 'card', 'right value';
is $m->stack->[0]->{wildcard}, 'hello/there', 'right value';
is $m->path_for, '/wildcards/1/hello/there', 'right path';
is $m->path_for(wildcard => ''), '/wildcards/1/', 'right path';
is @{$m->stack}, 1, 'right number of elements';
$m =
Mojolicious::Routes::Match->new(get => '/wildcards/2/hello/there')
Expand Down

0 comments on commit 76bc38c

Please sign in to comment.