1
0
Fork 0

Allow %-encoded colon after drive letter in URI

pull/56/head
Felix Becker 2016-10-12 00:53:21 +02:00
parent f81d03948b
commit 66b5176a43
2 changed files with 13 additions and 1 deletions

View File

@ -56,5 +56,11 @@ function uriToPath(string $uri)
throw new InvalidArgumentException("Not a valid file URI: $uri"); throw new InvalidArgumentException("Not a valid file URI: $uri");
} }
$filepath = urldecode($fragments['path']); $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;
} }

View File

@ -51,6 +51,12 @@ class FileUriTest extends TestCase
$uri = 'file:///c:/foo/bar.baz'; $uri = 'file:///c:/foo/bar.baz';
$this->assertEquals('c:\\foo\\bar.baz', uriToPath($uri)); $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() public function testUriToPathForUnknownProtocol()