fix(powershell): resolve SPECIFY_INIT_DIR without .NET Core-only API#3753
Open
Quratulain-bilal wants to merge 1 commit into
Open
fix(powershell): resolve SPECIFY_INIT_DIR without .NET Core-only API#3753Quratulain-bilal wants to merge 1 commit into
Quratulain-bilal wants to merge 1 commit into
Conversation
common.ps1 resolved the SPECIFY_INIT_DIR root with
[System.IO.Path]::TrimEndingDirectorySeparator, which only exists on .NET
Core. On Windows PowerShell 5.1 (.NET Framework) the call throws 'Method
invocation failed ... does not contain a method named
TrimEndingDirectorySeparator', so root resolution fails before any command
runs whenever SPECIFY_INIT_DIR is set. PowerShell 7+ users are unaffected,
which is why it went unnoticed.
The same file already documents this incompatibility ~150 lines later and
uses .TrimEnd('/','\') there. Apply the same approach here, guarding the one
case where the two differ — a bare drive root ('C:\'), where TrimEnd would
strip the separator and yield an invalid 'C:' — by preserving the original.
The existing @requires_pwsh tests in tests/test_init_dir.py already exercise
this path (trailing-slash, relative, precedence, compose); they now pass on
Windows PowerShell 5.1 as well as pwsh 7+.
Fixes github#3749
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3749
Problem
scripts/powershell/common.ps1resolves theSPECIFY_INIT_DIRroot with[System.IO.Path]::TrimEndingDirectorySeparator(...), which only exists on .NET Core. On Windows PowerShell 5.1 (.NET Framework) the call throws:so project-root resolution fails before any Spec Kit command can run whenever
SPECIFY_INIT_DIRis set. PowerShell 7+ users are unaffected (the API exists there), which is why it went unnoticed. The same file already documents this incompatibility ~150 lines later and correctly uses.TrimEnd('/','').Fix
Use the
.TrimEnd('/','')approach the file already endorses, guarding the single case where the two differ — a bare drive root (C:\), whereTrimEndwould strip the separator and yield an invalidC:— by preserving the original path there.Verification
Reproduced and verified on Windows PowerShell 5.1 (5.1.26100, Desktop edition):
THROWS: Method invocation failed ... TrimEndingDirectorySeparator.specify/detected.The existing
@requires_pwshtests intests/test_init_dir.pyalready exercise this path (trailing-slash, relative, precedence, compose). On PS 5.1 6 of them fail on the current code and all pass with this fix; they continue to pass on pwsh 7+. Edge cases confirmed:C:oo�ar\ -> C:oo�ar,C:oo/ -> C:oo,C:\ -> C:\(preserved), no-op when already clean.