Skip to content

Commit 2c2fea8

Browse files
authored
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
1 parent 4b4bd73 commit 2c2fea8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

scripts/powershell/common.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function Find-SpecifyRoot {
88

99
# Normalize to absolute path to prevent issues with relative paths
1010
# Use -LiteralPath to handle paths with wildcard characters ([, ], *, ?)
11-
$current = (Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue)?.Path
11+
$resolved = Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue
12+
$current = if ($resolved) { $resolved.Path } else { $null }
1213
if (-not $current) { return $null }
1314

1415
while ($true) {

0 commit comments

Comments
 (0)