Skip to content

Commit

Permalink
Fix crash when setBreakpoint from VSCode sends a git:/ URI... (#1000)
Browse files Browse the repository at this point in the history
* Fix git uri problem

* Remove unused imports
  • Loading branch information
rjmholt authored Aug 19, 2019
1 parent fd77c0d commit 974bb1d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/PowerShellEditorServices/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;

namespace Microsoft.PowerShell.EditorServices
{
Expand Down Expand Up @@ -49,6 +48,13 @@ public class Workspace
"**/*"
};

private static readonly string[] s_supportedUriSchemes = new[]
{
"file",
"untitled",
"inmemory"
};

private ILogger logger;
private Version powerShellVersion;
private Dictionary<string, ScriptFile> workspaceFiles = new Dictionary<string, ScriptFile>();
Expand Down Expand Up @@ -174,6 +180,20 @@ public ScriptFile GetFile(string filePath)
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
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);
Expand Down

0 comments on commit 974bb1d

Please sign in to comment.