Skip to content

Commit

Permalink
Merge pull request #5402 from magento-engcom/directory-is-exists-hanl…
Browse files Browse the repository at this point in the history
…ing-relative-paths

[Magento Community Engineering] Bugfix
  • Loading branch information
sivaschenko authored Mar 18, 2020
2 parents ecaa3b7 + 7f14a5b commit 55f3961
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ public function testGetRelativePathOutside()
$exceptions = 0;
$dir = $this->getDirectoryInstance('foo');
try {
$dir->getRelativePath(__DIR__ .'/ReadTest.php');
$dir->getRelativePath(__DIR__ . '/ReadTest.php');
} catch (ValidatorException $exception) {
$exceptions++;
}
try {
$dir->getRelativePath(__DIR__ .'//./..////Directory/ReadTest.php');
$dir->getRelativePath(__DIR__ . '//./..////Directory/ReadTest.php');
} catch (ValidatorException $exception) {
$exceptions++;
}
try {
$dir->getRelativePath(__DIR__ .'\..\Directory\ReadTest.php');
$dir->getRelativePath(__DIR__ . '\..\Directory\ReadTest.php');
} catch (ValidatorException $exception) {
$exceptions++;
}
Expand Down Expand Up @@ -222,7 +222,13 @@ public function testIsExist($dirPath, $path, $exists)
*/
public function existsProvider()
{
return [['foo', 'bar', true], ['foo', 'bar/baz/', true], ['foo', 'bar/notexists', false]];
return [
['foo', 'bar', true],
['foo', 'bar/baz/', true],
['foo', 'bar/notexists', false],
['foo', 'foo/../bar/', true],
['foo', 'foo/../notexists/', false]
];
}

public function testIsExistOutside()
Expand Down
14 changes: 8 additions & 6 deletions lib/internal/Magento/Framework/Filesystem/Directory/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\Exception\ValidatorException;

/**
* Filesystem directory instance for read operations
* @api
*/
class Read implements ReadInterface
Expand Down Expand Up @@ -40,8 +41,6 @@ class Read implements ReadInterface
private $pathValidator;

/**
* Constructor. Set properties.
*
* @param \Magento\Framework\Filesystem\File\ReadFactory $fileFactory
* @param \Magento\Framework\Filesystem\DriverInterface $driver
* @param string $path
Expand All @@ -60,6 +59,8 @@ public function __construct(
}

/**
* Validate the path is correct and within the directory
*
* @param null|string $path
* @param null|string $scheme
* @param bool $absolutePath
Expand Down Expand Up @@ -96,8 +97,7 @@ protected function setPath($path)
}

/**
* Retrieves absolute path
* E.g.: /var/www/application/file.txt
* Retrieves absolute path i.e. /var/www/application/file.txt
*
* @param string $path
* @param string $scheme
Expand Down Expand Up @@ -151,7 +151,7 @@ public function read($path = null)
/**
* Read recursively
*
* @param null $path
* @param string|null $path
* @throws ValidatorException
* @return string[]
*/
Expand Down Expand Up @@ -207,7 +207,9 @@ public function isExist($path = null)
{
$this->validatePath($path);

return $this->driver->isExists($this->driver->getAbsolutePath($this->path, $path));
return $this->driver->isExists(
$this->driver->getRealPathSafety($this->driver->getAbsolutePath($this->path, $path))
);
}

/**
Expand Down

0 comments on commit 55f3961

Please sign in to comment.