From 77c2fcc72e674924caf0bb8bc753fd3696008cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Nordl=C3=B6w?= Date: Tue, 19 Nov 2024 11:51:43 +0100 Subject: [PATCH] Use skipOver in uriToFile --- protocol/source/served/lsp/uri.d | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/protocol/source/served/lsp/uri.d b/protocol/source/served/lsp/uri.d index 06003dd6..7ffcc3a0 100644 --- a/protocol/source/served/lsp/uri.d +++ b/protocol/source/served/lsp/uri.d @@ -51,14 +51,13 @@ string uriToFile(DocumentUri uri) import std.uri : decodeComponent; import std.string : startsWith; - if (uri.startsWith("file://")) + if (uri.skipOver("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("/", "\\"); - return ret; + if (uri.length >= 3 && uri[0] == '/' && uri[2] == ':') // file:///x: windows path + return uri[1 .. $].replace("/", "\\"); + else if (uri.length >= 1 && uri[0] != '/') // file://share windows path + return "\\\\" ~ uri.replace("/", "\\"); + return uri; } else return null; @@ -283,7 +282,7 @@ unittest { assertEquals(uriNormalize(`b/../a.d`), `a.d`); assertEquals(uriNormalize(`b/../../a.d`), `../a.d`); - + foreach (prefix; ["file:///", "file://", "", "/", "//"]) { assertEquals(uriNormalize(prefix ~ `foo/bar/./a.d`), prefix ~ `foo/bar/a.d`);