Skip to content

Commit

Permalink
fix(url): normalize webroot path
Browse files Browse the repository at this point in the history
  • Loading branch information
montchr committed Nov 25, 2024
1 parent 3361c76 commit 99506a9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Support/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ public static function fromFilesystemPath(string $path): UriInterface
throw new UriSyntaxError('Target path must be absolute: ' . $path->value());
}

$webRoot = \app()->webRoot();
$webRoot = HierarchicalPath::new($webRoot)
->withoutDotSegments();

Assert::stringNotEmpty($path->value());
Assert::stringNotEmpty($webRoot->value());

// Strip the dirname common to webroot and target.
$relativePath = Str::after($path->value(), \app()->webRoot());
$relativePath = Str::after($path->value(), $webRoot->value());

// A filesystem path in the web root is an absolute URI path.
$uriPath = Path::new($relativePath)->withLeadingSlash();
Expand Down

0 comments on commit 99506a9

Please sign in to comment.