From cd0e7bc1b2a2a85b986d8ff85629e301f01fd6f1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 19 Aug 2019 16:45:47 -0700 Subject: [PATCH] Fix crash when setBreakpoint from VSCode sends a git:/ URI... (#1000) * Fix git uri problem * Remove unused imports --- .../Workspace/Workspace.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index b9ca0185a..0077af95b 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -29,6 +29,13 @@ public class Workspace "*.psd1" }; + private static readonly string[] s_supportedUriSchemes = new[] + { + "file", + "untitled", + "inmemory" + }; + private ILogger logger; private Version powerShellVersion; private Dictionary workspaceFiles = new Dictionary(); @@ -142,6 +149,20 @@ public ScriptFile GetFile(string filePath) /// The out parameter that will contain the ScriptFile object. public bool TryGetFile(string filePath, out ScriptFile scriptFile) { + try + { + if (filePath.Contains(":/") // Quick heuristic to determine if we might have a URI + && !s_supportedUriSchemes.Contains(new Uri(filePath).Scheme)) + { + scriptFile = null; + return false; + } + } + catch + { + // If something goes wrong trying to check for URIs, just proceed to normal logic + } + try { scriptFile = GetFile(filePath);