Skip to content

Commit

Permalink
canonicalize in-place
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 8, 2014
1 parent d57b910 commit 2f15c69
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 25 deletions.
3 changes: 0 additions & 3 deletions examples/connect-proxy.pl
@@ -1,7 +1,4 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojo::Base -strict;

use Mojo::IOLoop;

# Minimal CONNECT proxy server to test TLS tunneling
Expand Down
3 changes: 0 additions & 3 deletions examples/entities.pl
@@ -1,7 +1,4 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojo::Base -strict;

use Mojo::ByteStream 'b';
use Mojo::UserAgent;

Expand Down
2 changes: 0 additions & 2 deletions examples/fast.pl
@@ -1,5 +1,3 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojo::Base 'Mojolicious';

sub handler {
Expand Down
2 changes: 0 additions & 2 deletions examples/hello-template.pl
@@ -1,5 +1,3 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojolicious::Lite;

get '/hello';
Expand Down
2 changes: 0 additions & 2 deletions examples/hello.pl
@@ -1,5 +1,3 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojolicious::Lite;

get '/' => {data => 'Hello World!'};
Expand Down
3 changes: 0 additions & 3 deletions examples/microhttpd.pl
@@ -1,7 +1,4 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojo::Base -strict;

use Mojo::IOLoop;

# Minimal ioloop example demonstrating how to cheat at HTTP benchmarks :)
Expand Down
2 changes: 0 additions & 2 deletions examples/websocket.pl
@@ -1,5 +1,3 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
use Mojolicious::Lite;

websocket '/test' => sub {
Expand Down
14 changes: 6 additions & 8 deletions lib/Mojo/Path.pm
Expand Up @@ -13,16 +13,14 @@ has charset => 'UTF-8';
sub canonicalize {
my $self = shift;

my @parts;
for my $part (grep { $_ ne '.' && $_ ne '' } @{$self->parts}) {
if ($part ne '..') { push @parts, $part }

# ".."
else { @parts && $parts[-1] ne '..' ? pop @parts : push @parts, '..' }
my $parts = $self->parts;
for (my $i = 0; $i <= $#$parts;) {
if ($parts->[$i] eq '.' || $parts->[$i] eq '') { splice @$parts, $i, 1 }
elsif ($i < 1 || $parts->[$i] ne '..' || $parts->[$i - 1] eq '..') { $i++ }
else { splice @$parts, --$i, 2 }
}
$self->trailing_slash(undef) unless @parts;

return $self->parts(\@parts);
return @$parts ? $self : $self->trailing_slash(undef);
}

sub clone {
Expand Down

0 comments on commit 2f15c69

Please sign in to comment.