Skip to content

Commit

Permalink
Squashed 2 commits
Browse files Browse the repository at this point in the history
Remove redundant file_exists check, remove unnessissary ltrim call

added empty root path check in FileSystem loader constructor
  • Loading branch information
robfrawley committed Sep 6, 2016
1 parent 73901c1 commit f5f9689
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Binary/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
$this->mimeTypeGuesser = $mimeTypeGuesser;
$this->extensionGuesser = $extensionGuesser;

if (!($realRootPath = realpath($rootPath))) {
if (empty($rootPath) || !($realRootPath = realpath($rootPath))) {
throw new InvalidArgumentException(sprintf('Root image path not resolvable "%s"', $rootPath));
}

Expand All @@ -50,18 +50,14 @@ public function __construct(
*/
public function find($path)
{
if (!($absolutePath = realpath($this->rootPath.DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR)))) {
if (!($absolutePath = realpath($this->rootPath.DIRECTORY_SEPARATOR.$path))) {
throw new NotLoadableException(sprintf('Source image not resolvable "%s"', $path));
}

if (0 !== strpos($absolutePath, $this->rootPath)) {
throw new NotLoadableException(sprintf('Source image invalid "%s" as it is outside of the defined root path', $absolutePath));
}

if (false == file_exists($absolutePath)) {
throw new NotLoadableException(sprintf('Source image not found in "%s"', $absolutePath));
}

$mimeType = $this->mimeTypeGuesser->guess($absolutePath);

return new FileBinary(
Expand Down
14 changes: 14 additions & 0 deletions Tests/Binary/Loader/FileSystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public function testCouldBeConstructedWithExpectedArguments()
);
}

public function testThrowExceptionIfRootPathIsEmpty()
{
$this->setExpectedException(
'Liip\ImagineBundle\Exception\InvalidArgumentException',
'Root image path not resolvable'
);

new FileSystemLoader(
MimeTypeGuesser::getInstance(),
ExtensionGuesser::getInstance(),
''
);
}

public function testThrowExceptionIfRootPathDoesNotExist()
{
$this->setExpectedException(
Expand Down

1 comment on commit f5f9689

@dkorsak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this commit, projects with capfiony deployment tool does not work.
Image path is set as the .../release/web/uploads/image.jpg, but realpath returns .../shared/web/uploads/image.jpg and application throw exception because (0 !== strpos($absolutePath, $this->rootPath))

Please sign in to comment.