From 2c2fea8783f33085652b8c87e839bae84a6eb78d Mon Sep 17 00:00:00 2001 From: Manfred Riem <15701806+mnriem@users.noreply.github.com> Date: Wed, 25 Mar 2026 12:54:49 -0500 Subject: [PATCH] fix(ps1): replace null-conditional operator for PowerShell 5.1 compatibility (#1975) The `?.` (null-conditional member access) operator requires PowerShell 7.1+, but Windows ships with PowerShell 5.1 by default. When AI agents invoke .ps1 scripts on Windows, they typically use the system-associated handler (5.1), causing a ParseException: Unexpected token '?.Path'. Replace the single `?.` usage with a 5.1-compatible two-step pattern that preserves the same null-safety behavior. Fixes #1972 --- scripts/powershell/common.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index c67097773..7a96d3fac 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -8,7 +8,8 @@ function Find-SpecifyRoot { # Normalize to absolute path to prevent issues with relative paths # Use -LiteralPath to handle paths with wildcard characters ([, ], *, ?) - $current = (Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue)?.Path + $resolved = Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue + $current = if ($resolved) { $resolved.Path } else { $null } if (-not $current) { return $null } while ($true) {