From ced79cd1a1b6bab8110b2d36deb6897f7ac39171 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Tue, 1 Aug 2023 02:45:49 +0200 Subject: [PATCH] Use `OrdinalIgnoreCase` to lookup script breakpoints (#20046) --- .../engine/debugger/debugger.cs | 2 +- .../Debugging/DebuggerScriptTests.Tests.ps1 | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/debugger/debugger.cs b/src/System.Management.Automation/engine/debugger/debugger.cs index c91092772b..68b6d1a296 100644 --- a/src/System.Management.Automation/engine/debugger/debugger.cs +++ b/src/System.Management.Automation/engine/debugger/debugger.cs @@ -982,7 +982,7 @@ namespace System.Management.Automation _inBreakpoint = false; _idToBreakpoint = new ConcurrentDictionary(); // The string key is function context file path. The int key is sequencePoint index. - _pendingBreakpoints = new ConcurrentDictionary>(); + _pendingBreakpoints = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); _boundBreakpoints = new ConcurrentDictionary>>(StringComparer.OrdinalIgnoreCase); _commandBreakpoints = new ConcurrentDictionary(); _variableBreakpoints = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); diff --git a/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 b/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 index 1cf588427c..3dc799f169 100644 --- a/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 +++ b/test/powershell/Language/Scripting/Debugging/DebuggerScriptTests.Tests.ps1 @@ -643,3 +643,20 @@ Describe "Sometimes line breakpoints are ignored" -Tags "CI" { if (Test-Path -Path $tempFileName2) { Remove-Item $tempFileName2 -Force } } } + +Describe 'Breakpoints use case-insensitive match for script paths' -Tags 'CI' { + # https://github.com/PowerShell/PowerShell/issues/20044 + # Running on Windows only as Set-PSBreakpoint does case sensitive check on provided path on Unix + It 'Hits breakpoint' -Skip:(!$IsWindows) { + $filePath = Join-Path -Path $TestDrive -ChildPath 'demoIssue20044.ps1' + Set-Content -Path $filePath -Value "'Hello World'" + + $bp = Set-PSBreakpoint -Script $filePath.ToUpper() -Line 1 -Action { continue } + + & $filePath + + $bp.HitCount | Should -Be 1 + + if ($null -ne $bp) { Remove-PSBreakpoint $bp } + } +}