Skip to content

Commit 55f3961

Browse files
authored
Merge pull request #5402 from magento-engcom/directory-is-exists-hanling-relative-paths
[Magento Community Engineering] Bugfix
2 parents ecaa3b7 + 7f14a5b commit 55f3961

File tree

2 files changed

+18
-10
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory
  • lib/internal/Magento/Framework/Filesystem/Directory

2 files changed

+18
-10
lines changed

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/ReadTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ public function testGetRelativePathOutside()
7373
$exceptions = 0;
7474
$dir = $this->getDirectoryInstance('foo');
7575
try {
76-
$dir->getRelativePath(__DIR__ .'/ReadTest.php');
76+
$dir->getRelativePath(__DIR__ . '/ReadTest.php');
7777
} catch (ValidatorException $exception) {
7878
$exceptions++;
7979
}
8080
try {
81-
$dir->getRelativePath(__DIR__ .'//./..////Directory/ReadTest.php');
81+
$dir->getRelativePath(__DIR__ . '//./..////Directory/ReadTest.php');
8282
} catch (ValidatorException $exception) {
8383
$exceptions++;
8484
}
8585
try {
86-
$dir->getRelativePath(__DIR__ .'\..\Directory\ReadTest.php');
86+
$dir->getRelativePath(__DIR__ . '\..\Directory\ReadTest.php');
8787
} catch (ValidatorException $exception) {
8888
$exceptions++;
8989
}
@@ -222,7 +222,13 @@ public function testIsExist($dirPath, $path, $exists)
222222
*/
223223
public function existsProvider()
224224
{
225-
return [['foo', 'bar', true], ['foo', 'bar/baz/', true], ['foo', 'bar/notexists', false]];
225+
return [
226+
['foo', 'bar', true],
227+
['foo', 'bar/baz/', true],
228+
['foo', 'bar/notexists', false],
229+
['foo', 'foo/../bar/', true],
230+
['foo', 'foo/../notexists/', false]
231+
];
226232
}
227233

228234
public function testIsExistOutside()

lib/internal/Magento/Framework/Filesystem/Directory/Read.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\ValidatorException;
1010

1111
/**
12+
* Filesystem directory instance for read operations
1213
* @api
1314
*/
1415
class Read implements ReadInterface
@@ -40,8 +41,6 @@ class Read implements ReadInterface
4041
private $pathValidator;
4142

4243
/**
43-
* Constructor. Set properties.
44-
*
4544
* @param \Magento\Framework\Filesystem\File\ReadFactory $fileFactory
4645
* @param \Magento\Framework\Filesystem\DriverInterface $driver
4746
* @param string $path
@@ -60,6 +59,8 @@ public function __construct(
6059
}
6160

6261
/**
62+
* Validate the path is correct and within the directory
63+
*
6364
* @param null|string $path
6465
* @param null|string $scheme
6566
* @param bool $absolutePath
@@ -96,8 +97,7 @@ protected function setPath($path)
9697
}
9798

9899
/**
99-
* Retrieves absolute path
100-
* E.g.: /var/www/application/file.txt
100+
* Retrieves absolute path i.e. /var/www/application/file.txt
101101
*
102102
* @param string $path
103103
* @param string $scheme
@@ -151,7 +151,7 @@ public function read($path = null)
151151
/**
152152
* Read recursively
153153
*
154-
* @param null $path
154+
* @param string|null $path
155155
* @throws ValidatorException
156156
* @return string[]
157157
*/
@@ -207,7 +207,9 @@ public function isExist($path = null)
207207
{
208208
$this->validatePath($path);
209209

210-
return $this->driver->isExists($this->driver->getAbsolutePath($this->path, $path));
210+
return $this->driver->isExists(
211+
$this->driver->getRealPathSafety($this->driver->getAbsolutePath($this->path, $path))
212+
);
211213
}
212214

213215
/**

0 commit comments

Comments
 (0)