Skip to content

Commit

Permalink
include File::Spec::Unix code to Path::Router
Browse files Browse the repository at this point in the history
Signed-off-by: Stevan Little <stevan.little@iinteractive.com>
  • Loading branch information
lestrrat authored and Stevan Little committed Mar 11, 2009
1 parent f79c40e commit 153b630
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Path/Router.pm
Expand Up @@ -46,7 +46,6 @@ sub _build_match_code {
" my \$self = shift;\n" .
" my \$path = shift;\n" .
" my \$routes = \$self->routes;\n" .
# "print STDERR \"Matching \$path\\n\";\n" .
join("\n", @code) .
"#line " . __LINE__ . ' "' . __FILE__ . "\"\n" .
" print STDERR \"match failed\\n\" if DEBUG();\n" .
Expand Down Expand Up @@ -90,9 +89,15 @@ sub match {
my ($self, $url) = @_;

if ($self->inline) {
my $canonpath = File::Spec::Unix->canonpath($url);
$canonpath =~ s/^\///;
return $self->match_code->($self, $canonpath);
$url =~ s|/{2,}|/|g; # xx////xx -> xx/xx
$url =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx
$url =~ s|^(?:\./)+||s unless $url eq "./"; # ./xx -> xx
$url =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx
$url =~ s|^/\.\.$|/|; # /.. -> /
$url =~ s|/\z|| unless $url eq "/"; # xx/ -> xx
$url =~ s|^/||; # Path::Router specific. remove first /

return $self->match_code->($self, $url);
} else {
my @parts = grep { defined $_ and length $_ }
split '/' => File::Spec::Unix->canonpath($url);
Expand Down

0 comments on commit 153b630

Please sign in to comment.