Skip to content

Commit 66ba44e

Browse files
committed
Validate hashtable key is not null in the debug service
The `scriptPath` (which amusingly could also be a script block) is used as a key in a hashtable of breakpoints in the debug service. To avoid a (that specifically showed up in the unit tests), we validate that a non-empty (and non-null) value is provided.
1 parent 7c41c5b commit 66ba44e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
using System.Management.Automation.Language;
99
using System.Reflection;
1010
using System.Text;
11-
using System.Threading.Tasks;
12-
using Microsoft.PowerShell.EditorServices.Utility;
1311
using System.Threading;
12+
using System.Threading.Tasks;
1413
using Microsoft.Extensions.Logging;
15-
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
16-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1714
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
15+
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
16+
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
17+
using Microsoft.PowerShell.EditorServices.Utility;
1818

1919
namespace Microsoft.PowerShell.EditorServices.Services
2020
{
@@ -988,6 +988,7 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
988988
// this for CommandBreakpoint, as those span all script files.
989989
if (e.Breakpoint is LineBreakpoint lineBreakpoint)
990990
{
991+
// TODO: This could be either a path or a script block!
991992
string scriptPath = lineBreakpoint.Script;
992993
if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
993994
this.remoteFileManager != null)
@@ -1008,6 +1009,10 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
10081009
scriptPath = mappedPath;
10091010
}
10101011

1012+
// TODO: It is very strange that we use the path as the key, which it could also be
1013+
// a script block.
1014+
Validate.IsNotNullOrEmptyString(nameof(scriptPath), scriptPath);
1015+
10111016
// Normalize the script filename for proper indexing
10121017
string normalizedScriptName = scriptPath.ToLower();
10131018

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetails.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal static BreakpointDetails Create(
5858
string hitCondition = null,
5959
string logMessage = null)
6060
{
61-
Validate.IsNotNull("source", source);
61+
Validate.IsNotNullOrEmptyString(nameof(source), source);
6262

6363
return new BreakpointDetails
6464
{

0 commit comments

Comments
 (0)