From 47472252a758cdf87204bfa4f5f2ec7b368c3b70 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Mon, 7 Nov 2016 10:24:49 +0100 Subject: [PATCH] Encode spaces in paths to %20 instead of + (#140) --- src/utils.php | 2 +- tests/Utils/FileUriTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.php b/src/utils.php index 810fbc1..58b07ea 100644 --- a/src/utils.php +++ b/src/utils.php @@ -39,7 +39,7 @@ function pathToUri(string $filepath): string if (substr($first, -1) !== ':') { $first = urlencode($first); } - $parts = array_map('urlencode', $parts); + $parts = array_map('rawurlencode', $parts); array_unshift($parts, $first); $filepath = implode('/', $parts); return 'file:///' . $filepath; diff --git a/tests/Utils/FileUriTest.php b/tests/Utils/FileUriTest.php index 62d715f..4737314 100644 --- a/tests/Utils/FileUriTest.php +++ b/tests/Utils/FileUriTest.php @@ -25,7 +25,7 @@ class FileUriTest extends TestCase // special chars are escaped $uri = pathToUri('c:/path/to/file/dürüm döner.php'); - $this->assertEquals('file:///c:/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php', $uri); + $this->assertEquals('file:///c:/path/to/file/d%C3%BCr%C3%BCm%20d%C3%B6ner.php', $uri); //backslashes are transformed $uri = pathToUri('c:\\foo\\bar.baz');