Skip to content

Commit

Permalink
check for scheme properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 4, 2023
1 parent 9985ef7 commit 4b86e27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/File/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use function explode;
use function implode;
use function ltrim;
use function preg_match;
use function rtrim;
use function str_contains;
use function str_replace;
use function strlen;
use function strpos;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function absolutizePath(string $path): string
return $path;
}
}
if (str_contains($path, '://')) {
if (preg_match('~^[a-z0-9+\-.]+://~i', $path) === 1) {
return $path;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/PHPStan/File/FileHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function dataAbsolutizePathOnWindows(): array
['users', 'C:\abcd\users'],
['../lib', 'C:\abcd\../lib'],
['./lib', 'C:\abcd\./lib'],
['vfs://a\b', 'vfs://a\b'],
['vFs-v1.0://a\b', 'vFs-v1.0://a\b'],
['./x://a\b', 'C:\abcd\./x://a\b'],
];
}

Expand Down Expand Up @@ -48,7 +49,8 @@ public function dataAbsolutizePathOnLinuxOrMac(): array
['../lib', '/abcd/../lib'],
['./lib', '/abcd/./lib'],
['phar:///home/users/', 'phar:///home/users/'],
['vfs://a/b', 'vfs://a/b'],
['vFs-v1.0://a/b', 'vFs-v1.0://a/b'],
['./x://a/b', '/abcd/./x://a/b'],
];
}

Expand Down

0 comments on commit 4b86e27

Please sign in to comment.