Skip to content

Commit

Permalink
strpos($location, "/") === 0 is not a valid way to detect absolute …
Browse files Browse the repository at this point in the history
…paths on Windows: it fails on `D:/a/cli/cli/config/…`.
  • Loading branch information
wimleers committed Jun 19, 2023
1 parent a694e0e commit da056f6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Command/App/NewFromDrupal7Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ private function getLocation(string $location, bool $should_exist = TRUE): strin
elseif (!$file_exists && $should_exist) {
throw new ValidatorException(sprintf('%s could not be located. Check that the path is correct and try again.', $location));
}
if (strpos($location, '.') === 0 || strpos($location, '/') !== 0) {
if (strpos($location, '.') === 0 || !static::isAbsolutePath($location)) {
$absolute = getcwd() . '/' . $location;
$location = $should_exist ? realpath($absolute) : $absolute;
}
}
return $location;
}

private static function isAbsolutePath(string $path): bool {
if ($path === '') {
throw new \InvalidArgumentException();
}
// @see https://stackoverflow.com/a/23570509
return $path[0] === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0;
}

protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$inspector = $this->getInspector($input);
Expand Down

0 comments on commit da056f6

Please sign in to comment.