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;