Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/internal/Magento/Framework/Filesystem/Driver/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,13 @@ public function fileUnlock($resource)
*/
public function getAbsolutePath($basePath, $path, $scheme = null)
{
// check if the path given is already an absolute path containing the
// basepath. so if the basepath starts at position 0 in the path, we
// must not concatinate them again because path is already absolute.
if (0 === strpos($path, $basePath)) {
return $this->getScheme($scheme) . $path;
}

return $this->getScheme($scheme) . $basePath . ltrim($this->fixSeparator($path), '/');
}

Expand Down
7 changes: 7 additions & 0 deletions lib/internal/Magento/Framework/Filesystem/Driver/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public function fileReadLine($resource, $length, $ending = null)
*/
public function getAbsolutePath($basePath, $path, $scheme = null)
{
// check if the path given is already an absolute path containing the
// basepath. so if the basepath starts at position 0 in the path, we
// must not concatinate them again because path is already absolute.
if (0 === strpos($path, $basePath)) {
return $this->getScheme() . $path;
}

return $this->getScheme() . $basePath . $path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function testGetAbsolutePath($basePath, $path, $expected)
$file = new File();
$this->assertEquals($expected, $file->getAbsolutePath($basePath, $path));
}

public function dataProviderForTestGetAbsolutePath()
{
return [
['/root/path/', 'sub', '/root/path/sub'],
['/root/path/', '/sub', '/root/path/sub'],
['/root/path/', '../sub', '/root/path/../sub'],
['/root/path/', '/root/path/sub', '/root/path/root/path/sub'],
['/root/path/', '/root/path/sub', '/root/path/sub'],
];
}

Expand Down