Skip to content

Commit 47ad46a

Browse files
committed
Correction on relative paths
1 parent b1edf50 commit 47ad46a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Dispatch.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Packaged\Dispatch;
33

4+
use Packaged\Dispatch\Resources\AbstractDispatchableResource;
45
use Packaged\Dispatch\Resources\AbstractResource;
56
use Packaged\Dispatch\Resources\DispatchableResource;
67
use Packaged\Dispatch\Resources\ResourceFactory;
@@ -115,7 +116,8 @@ public function handle(Request $request): Response
115116
//Remove the hash from the URL
116117
$compareHash = array_shift($pathParts);
117118

118-
$fullPath = $manager->getFilePath(Path::custom('/', $pathParts));
119+
$requestPath = Path::custom('/', $pathParts);
120+
$fullPath = $manager->getFilePath($requestPath);
119121
if($compareHash !== $manager->getFileHash($fullPath))
120122
{
121123
return Response::create("File Not Found", 404);
@@ -126,6 +128,10 @@ public function handle(Request $request): Response
126128
{
127129
$resource->setManager($manager);
128130
}
131+
if($resource instanceof AbstractDispatchableResource)
132+
{
133+
$resource->setProcessingPath($requestPath);
134+
}
129135
if($resource instanceof AbstractResource)
130136
{
131137
$resource->setFilePath($fullPath);

src/Resources/AbstractDispatchableResource.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ protected function makeFullPath($relativePath, $workingDirectory)
125125
{
126126
$relativePath = str_replace('../', '', $relativePath);
127127
$workingDirectoryParts = explode('/', $workingDirectory);
128-
if($levelUps > count($workingDirectoryParts))
128+
$moves = count($workingDirectoryParts) - $levelUps;
129+
if($moves < 0)
129130
{
130131
//Relative to this directory is not allowed
131132
return null;
132133
}
133-
return implode('/', array_slice($workingDirectoryParts, $levelUps)) . $relativePath;
134+
return Path::custom('/', array_merge(array_slice($workingDirectoryParts, 0, $moves), [$relativePath]));
134135
}
135136
return $relativePath;
136137
}

0 commit comments

Comments
 (0)