From da056f6cf366322d3bcbb6f12053bdac05fed59d Mon Sep 17 00:00:00 2001 From: Wim Leers Date: Mon, 19 Jun 2023 18:24:01 +0200 Subject: [PATCH] =?UTF-8?q?`strpos($location,=20"/")=20=3D=3D=3D=200`=20is?= =?UTF-8?q?=20not=20a=20valid=20way=20to=20detect=20absolute=20paths=20on?= =?UTF-8?q?=20Windows:=20it=20fails=20on=20`D:/a/cli/cli/config/=E2=80=A6`?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Command/App/NewFromDrupal7Command.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Command/App/NewFromDrupal7Command.php b/src/Command/App/NewFromDrupal7Command.php index 93a9c0f09..bced3903d 100644 --- a/src/Command/App/NewFromDrupal7Command.php +++ b/src/Command/App/NewFromDrupal7Command.php @@ -95,7 +95,7 @@ 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; } @@ -103,6 +103,14 @@ private function getLocation(string $location, bool $should_exist = TRUE): strin 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);