diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs index 5e181e954..43d3c9d62 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs @@ -194,9 +194,9 @@ private static string GetValueStringAndType(object value, bool isExpandable, out else { string valueToString = value.SafeToString(); - if (valueToString.Equals(objType.ToString())) + if (valueToString == null || valueToString.Equals(objType.ToString())) { - // If the ToString() matches the type name, then display the type + // If the ToString() matches the type name or is null, then display the type // name in PowerShell format. string shortTypeName = objType.Name; diff --git a/test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1 b/test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1 index fc6896990..13701d0c2 100644 --- a/test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1 +++ b/test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1 @@ -12,6 +12,7 @@ function Test-Variables { $classVar.Name = "Test" $classVar.Number = 42; $enumVar = $ErrorActionPreference + $nullString = [NullString]::Value $psObjVar = New-Object -TypeName PSObject -Property @{Name = 'John'; Age = 75} $psCustomObjVar = [PSCustomObject] @{Name = 'Paul'; Age = 73} $procVar = Get-Process system diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index 9b430cd1a..fe88e7fd8 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -815,6 +815,34 @@ await this.debugService.SetLineBreakpointsAsync( this.powerShellContext.AbortExecution(); } + [Fact] + public async Task DebufferVariableNullStringDisplaysCorrectly() + { + await this.debugService.SetLineBreakpointsAsync( + this.variableScriptFile, + new[] { BreakpointDetails.Create("", 18) }); + + // Execute the script and wait for the breakpoint to be hit + Task executeTask = + this.powerShellContext.ExecuteScriptStringAsync( + this.variableScriptFile.FilePath); + + await this.AssertDebuggerStopped(this.variableScriptFile.FilePath); + + StackFrameDetails[] stackFrames = debugService.GetStackFrames(); + + VariableDetailsBase[] variables = + debugService.GetVariables(stackFrames[0].LocalVariables.Id); + + var nullStringVar = variables.FirstOrDefault(v => v.Name == "$nullString"); + Assert.NotNull(nullStringVar); + Assert.True("[NullString]".Equals(nullStringVar.ValueString)); + Assert.True(nullStringVar.IsExpandable); + + // Abort execution of the script + this.powerShellContext.AbortExecution(); + } + [Fact] public async Task DebuggerVariablePSObjectDisplaysCorrectly() {