Skip to content

Commit

Permalink
fixed small stringification bug in Mojo::Path
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 12, 2012
1 parent 56d0a5b commit 0f12d1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added merge method to Mojo::Path.
- Improved documentation.
- Improved tests.
- Fixed small stringification bug in Mojo::Path.

2.95 2012-05-10
- Improved documentation.
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojo/Path.pm
Expand Up @@ -71,7 +71,7 @@ sub merge {
pop @{$self->parts} unless $self->trailing_slash;
$path = $self->new($path);
push @{$self->parts}, @{$path->parts};
return $self->leading_slash(1)->trailing_slash($path->trailing_slash);
return $self->trailing_slash($path->trailing_slash);
}

sub parse {
Expand All @@ -86,8 +86,9 @@ sub parse {
}

sub to_abs_string {
my $self = shift;
return $self->leading_slash ? $self->to_string : ('/' . $self->to_string);
my $self = shift;
my $string = $self->to_string;
return $self->leading_slash ? $string : $string ? "/$string" : '';
}

# "How is education supposed to make me feel smarter?
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/URL.pm
Expand Up @@ -221,7 +221,7 @@ sub to_string {
$url .= $url ? $authority : $authority ? "//$authority" : '';

# Path
$url .= $self->path;
$url .= $url ? $self->path->to_abs_string : $self->path->to_string;

# Query
my $query = join '', $self->query;
Expand Down
8 changes: 4 additions & 4 deletions t/mojo/path.t
Expand Up @@ -196,10 +196,10 @@ $path->merge('/bar/baz/');
is "$path", '/bar/baz/', 'right path';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('/foo/bar');
$path->merge(Mojo::Path->new('baz/yada'));
is "$path", '/foo/baz/yada', 'right path';
ok $path->leading_slash, 'has leading slash';
$path = Mojo::Path->new('foo/bar');
$path->merge('baz/yada');
is "$path", 'foo/baz/yada', 'right path';
ok !$path->leading_slash, 'no leading slash';
ok !$path->trailing_slash, 'no trailing slash';

# Empty path elements
Expand Down

0 comments on commit 0f12d1b

Please sign in to comment.