From 74085792afafb3ce39cbe93b88de37db836171b4 Mon Sep 17 00:00:00 2001 From: Alexandru Militaru Date: Tue, 19 Nov 2024 12:29:23 +0200 Subject: [PATCH] uriToFile: Ensure Linux relative paths are not mistaken for Windows network paths --- protocol/source/served/lsp/uri.d | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/protocol/source/served/lsp/uri.d b/protocol/source/served/lsp/uri.d index 06003dd6..8f52b356 100644 --- a/protocol/source/served/lsp/uri.d +++ b/protocol/source/served/lsp/uri.d @@ -54,10 +54,12 @@ string uriToFile(DocumentUri uri) if (uri.startsWith("file://")) { string ret = uri["file://".length .. $].decodeComponent; - if (ret.length >= 3 && ret[0] == '/' && ret[2] == ':') // file:///x: windows path - return ret[1 .. $].replace("/", "\\"); - else if (ret.length >= 1 && ret[0] != '/') // file://share windows path - return "\\\\" ~ ret.replace("/", "\\"); + version(Windows) { + if (ret.length >= 3 && ret[0] == '/' && ret[2] == ':') // file:///x: windows path + return ret[1 .. $].replace("/", "\\"); + else if (ret.length >= 1 && ret[0] != '/') // file://share windows path + return "\\\\" ~ ret.replace("/", "\\"); + } return ret; } else @@ -86,6 +88,7 @@ string uriToFile(DocumentUri uri) else version (Posix) { testUri(`/home/pi/.bashrc`, `file:///home/pi/.bashrc`); + testUri(`pi/.bashrc`, `file://pi/.bashrc`); testUri(`/home/pi/Development Projects/D-code`, `file:///home/pi/Development%20Projects/D-code`); }