Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uriToFile: Ensure Linux relative paths are not mistaken for Windows network paths #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Jan wants a newline here for conformance.

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
Loading