From 153b63083e4b7dbd72578af289e4fde2e9f4b1a9 Mon Sep 17 00:00:00 2001 From: "Daisuke Maki (lestrrat)" Date: Sun, 8 Mar 2009 09:56:58 +0800 Subject: [PATCH] include File::Spec::Unix code to Path::Router Signed-off-by: Stevan Little --- lib/Path/Router.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Path/Router.pm b/lib/Path/Router.pm index 0538f89..bf1c14f 100644 --- a/lib/Path/Router.pm +++ b/lib/Path/Router.pm @@ -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" . @@ -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);