Skip to content

Commit

Permalink
uriToFile: Ensure Linux relative paths are not mistaken for Windows n…
Browse files Browse the repository at this point in the history
…etwork paths
  • Loading branch information
alexandrumc committed Nov 19, 2024
1 parent 1c19fd2 commit 7408579
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions protocol/source/served/lsp/uri.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`);
}

Expand Down

0 comments on commit 7408579

Please sign in to comment.