diff --git a/src/utils.php b/src/utils.php index 3c058e2..c89c2d3 100644 --- a/src/utils.php +++ b/src/utils.php @@ -56,5 +56,11 @@ function uriToPath(string $uri) throw new InvalidArgumentException("Not a valid file URI: $uri"); } $filepath = urldecode($fragments['path']); - return strpos($filepath, ':') === false ? $filepath : str_replace('/', '\\', $filepath); + if (strpos($filepath, ':') !== false) { + if ($filepath[0] === '/') { + $filepath = substr($filepath, 1); + } + $filepath = str_replace('/', '\\', $filepath); + } + return $filepath; } diff --git a/tests/Utils/FileUriTest.php b/tests/Utils/FileUriTest.php index a9d3559..62d715f 100644 --- a/tests/Utils/FileUriTest.php +++ b/tests/Utils/FileUriTest.php @@ -51,6 +51,12 @@ class FileUriTest extends TestCase $uri = 'file:///c:/foo/bar.baz'; $this->assertEquals('c:\\foo\\bar.baz', uriToPath($uri)); + + $uri = 'file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php'; + $this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', uriToPath($uri)); + + $uri = 'file:///c%3A/foo/bar.baz'; + $this->assertEquals('c:\\foo\\bar.baz', uriToPath($uri)); } public function testUriToPathForUnknownProtocol()