Skip to content

Commit

Permalink
Fix URI with query parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Sep 20, 2023
1 parent 91ebb5f commit d9235ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
Expand Down Expand Up @@ -221,6 +222,11 @@ public static IPath filePathFromURI(String uriStr) {
public static IPath canonicalFilePathFromURI(String uriStr) {
URI uri = URI.create(uriStr);
if ("file".equals(uri.getScheme())) {
try {
uri = new URI(uri.getScheme(), null, uri.getPath(), null, null);
} catch (URISyntaxException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
return FileUtil.canonicalPath(Path.fromOSString(Paths.get(uri).toString()));
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ public void testGetLongestCommonPath() {
assertNotNull(commonPath);
assertEquals("/work/src/org/eclipse", commonPath.toPortableString());
}

@Test
public void testURIWithQuery() {
String uriStr = "file:///home/user/vscode?windowId=_blank";
IPath path = ResourceUtils.canonicalFilePathFromURI(uriStr);
assertEquals("/home/user/vscode", path.toString());
}
}

0 comments on commit d9235ba

Please sign in to comment.