Skip to content

Commit

Permalink
Merge pull request #1076 from robfrawley/feature-locator-check-is-rea…
Browse files Browse the repository at this point in the history
…dable

[Data Locator] Check if file is readable in file system loactor
  • Loading branch information
cedricziel committed Mar 21, 2018
2 parents 6d1df78 + 5555645 commit 7700c5a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Binary/Locator/FileSystemLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ private function sanitizeRootPath(string $path): string
*/
private function sanitizeAbsolutePath(string $path): string
{
foreach ($this->roots as $root) {
if (0 === mb_strpos($path, $root)) {
return $path;
}
$roots = array_filter($this->roots, function (string $root) use ($path): bool {
return 0 === mb_strpos($path, $root);
});

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

throw new NotLoadableException(sprintf('Source image invalid "%s" as it is outside of the defined root path(s) "%s"',
$path, implode(':', $this->roots)));
if (!is_readable($path)) {
throw new NotLoadableException(sprintf('Source image invalid "%s" as it is not readable', $path));
}

return $path;
}
}

0 comments on commit 7700c5a

Please sign in to comment.