From 27be625560d61856d40018715738595be36ab109 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 1 Mar 2017 20:23:25 +0100 Subject: [PATCH] Replace merge_paths with Path::Tiny: This was a bit hard to figure out, but with the help of @wchristian, it seems as though this merges path from argument 1 onto argument 2. I have this replaced it with a single path() call. All tests pass, so I hope this is okay. We should run these tests under Windows to make sure it works there as well. --- lib/Dancer2/Core/App.pm | 2 +- lib/Dancer2/Handler/File.pm | 20 +------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index 69d8132e5..f0211c39e 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -1019,7 +1019,7 @@ sub send_file { || $self->config->{public_dir} || Path::Tiny::path( $self->location, 'public' )->stringify; - $file_path = Dancer2::Handler::File->merge_paths( $path, $dir ); + $file_path = Path::Tiny::path( $dir, $path )->stringify; my $err_response = sub { my $status = shift; $self->response->status($status); diff --git a/lib/Dancer2/Handler/File.pm b/lib/Dancer2/Handler/File.pm index 2dbcfbec8..2949fc966 100644 --- a/lib/Dancer2/Handler/File.pm +++ b/lib/Dancer2/Handler/File.pm @@ -85,7 +85,7 @@ sub code { $path =~ s/^\Q$prefix\E//; } - my $file_path = $self->merge_paths( $path, $self->public_dir ); + my $file_path = Path::Tiny::path( $self->public_dir, $path )->stringify; return $self->standard_response( $app, 403 ) if !defined $file_path; if ( !-f $file_path ) { @@ -130,22 +130,4 @@ sub code { }; } -sub merge_paths { - my ( undef, $path, $public_dir ) = @_; - - my ( $volume, $dirs, $file ) = File::Spec->splitpath( $path ); - my @tokens = File::Spec->splitdir( "$dirs$file" ); - my $updir = File::Spec->updir; - return if grep $_ eq $updir, @tokens; - - my ( $pub_vol, $pub_dirs, $pub_file ) = File::Spec->splitpath( $public_dir ); - my @pub_tokens = File::Spec->splitdir( "$pub_dirs$pub_file" ); - return if length $volume and length $pub_vol and $volume ne $pub_vol; - - my @final_vol = ( length $pub_vol ? $pub_vol : length $volume ? $volume : () ); - my @file_path = ( @final_vol, @pub_tokens, @tokens ); - my $file_path = path( @file_path ); - return $file_path; -} - 1;