Skip to content

fix(ps1): replace null-conditional operator for PowerShell 5.1 compatibility#1975

Merged
mnriem merged 1 commit intogithub:mainfrom
mnriem:fix/issue-1972-ps1-null-conditional
Mar 25, 2026
Merged

fix(ps1): replace null-conditional operator for PowerShell 5.1 compatibility#1975
mnriem merged 1 commit intogithub:mainfrom
mnriem:fix/issue-1972-ps1-null-conditional

Conversation

@mnriem
Copy link
Collaborator

@mnriem mnriem commented Mar 25, 2026

Summary

Replaces the ?. (null-conditional member access) operator in scripts/powershell/common.ps1 with a PowerShell 5.1-compatible pattern.

Problem

The ?. operator requires PowerShell 7.1+, but Windows ships with PowerShell 5.1 by default. When AI agents (e.g., Cursor) invoke .ps1 scripts on Windows, they typically use the system-associated handler (Windows PowerShell 5.1), causing:

Unexpected token '?.Path' in expression or statement.

This breaks all spec-kit script execution on Windows for users without PowerShell 7+ installed, since common.ps1 is sourced by every other script.

Fix

Single-line change in scripts/powershell/common.ps1 line 11:

# Before (requires PS 7.1+)
$current = (Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue)?.Path

# After (works on PS 5.1+)
$resolved = Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue
$current = if ($resolved) { $resolved.Path } else { $null }

The replacement preserves identical null-safety behavior.

Audit

Performed a comprehensive scan of all 6 .ps1 files for PowerShell 7+ syntax features (?., ??, ??=, &&/|| pipeline chains, ternary operators, -Parallel, 7.0+ cmdlets). This was the only instance. The CI script (create-release-packages.ps1) intentionally requires 7.0 via #requires but only runs in GitHub Actions.

Fixes #1972

…ibility

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 github#1972
Copilot AI review requested due to automatic review settings March 25, 2026 17:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores Windows PowerShell 5.1 compatibility for spec-kit’s shared PowerShell helpers by removing the PowerShell 7+ null-conditional member access operator from common.ps1, fixing script execution failures reported in #1972.

Changes:

  • Replaced ?.Path usage with a PowerShell 5.1-compatible null-safe pattern when resolving $StartDir.
  • Preserved the prior behavior where an unresolved path yields $null.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mnriem mnriem merged commit 2c2fea8 into github:main Mar 25, 2026
12 checks passed
@mnriem mnriem deleted the fix/issue-1972-ps1-null-conditional branch March 25, 2026 17:54
RbBtSn0w pushed a commit to RbBtSn0w/spec-kit that referenced this pull request Mar 26, 2026
…ibility (github#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 github#1972
jonasbokim added a commit to Jonas-Construction-Software/jonas-spec-kit-dev that referenced this pull request Mar 26, 2026
…nc-main-2026-03-25

* upstream/main: (90 commits)
  fix(ps1): replace null-conditional operator for PowerShell 5.1 compatibility (github#1975)
  chore: bump version to 0.4.2 (github#1973)
  feat: Auto-register ai-skills for extensions whenever applicable (github#1840)
  docs: add manual testing guide for slash command validation (github#1955)
  Add AIDE, Extensify, and Presetify to community extensions (github#1961)
  docs: add community presets section to main README (github#1960)
  docs: move community extensions table to main README for discoverability (github#1959)
  docs(readme): consolidate Community Friends sections and fix ToC anchors (github#1958)
  fix(commands): rename NFR references to success criteria in analyze and clarify (github#1935)
  Add Community Friends section to README (github#1956)
  docs: add Community Friends section with Spec Kit Assistant VS Code extension (github#1944)
  chore: bump version to 0.4.1 (github#1953)
  Add checkpoint extension (github#1947)
  fix(scripts): prioritize .specify over git for repo root detection (github#1933)
  docs: add AIDE extension demo to community projects (github#1943)
  fix(templates): add missing Assumptions section to spec template (github#1939)
  chore: bump version to 0.4.0 (github#1937)
  fix(cli): add allow_unicode=True and encoding="utf-8" to YAML I/O (github#1936)
  fix(codex): native skills fallback refresh + legacy prompt suppression (github#1930)
  feat(cli): embed core pack in wheel for offline/air-gapped deployment (github#1803)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Script execution failure (.ps1)

2 participants