-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Set-Location should use path with wildcard characters if it exists instead of globbing #5839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nt working directory, but if the directory name contains PowerShell wildcard characters, it fails and reverts to $PSHOME. Fix is to suppress wildcard expansion in this case.
337ce57 to
e7912fe
Compare
|
|
||
| It "Can start in directory where name contains wildcard characters" { | ||
| Set-Location -LiteralPath $testPath.FullName | ||
| & $powershell -noprofile -c get-location | Should BeExactly $testPath.FullName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$powershell don't defined in the Describe block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix. Broke when I made this test it's own Describe.
lzybkr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change is surprising given the PR title. Based on the code, I would have thought that Set-Location was broken. Given that it's not, I'm guessing similar code exists elsewhere and either:
a) that code is not necessary
b) that code is subtly different than this fix
So I'd ask for a little more digging. You might also look for other ways this code is reachable - that might suggest the need for more tests.
|
@lzybkr Changed title a bit to clarify where the issue is. This internal |
|
With your change - I think Before your change, this reports an error, after it works without error. I think this is desirable - it almost seems like |
|
@lzybkr you are correct regarding the behavior change in |
|
If |
|
After adding test for |
|
|
||
| if (!context.SuppressWildcardExpansion) | ||
| // if the directory contains wildcard characters, but exists, just return it | ||
| if (!context.SuppressWildcardExpansion && !Utils.NativeDirectoryExists(userPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the comment and logic should be "if the directory exists, just return it"? And wildcard characters should be a next check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leveraging falling into the else clause which is the same as if wildcard expansion is suppressed. Alternatively, I could rearrange the code so that the suppression/existing happens first which may make it a bit easier to read:
if (context.SuppressWildcardExpansion || Utils.NativeDirectoryExists(userPath))
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change this code to handle exceptions during check
2265cf6 to
cc24a84
Compare
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@lzybkr Could you please continue the review? |
lzybkr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sign off.
You should squash the commits and write a good commit message with an explanation of the breaking change so that appears in the git history.
|
@SteveL-MSFT Could you please edit PR header and description to address Jason request? |
|
Done |
|
I'm a bit late to the party, but I hope it's OK now, while 6.1.0 still in preview. Something with implemented fix still bothers me. While this might even make it work as expected more times than before, it has an increased level of surprise. It might make issues caused by the use of I also wonder why it was made in this way instead of just calling |
|
@KillyMXI you bring up some good points, can you open a new issue to discuss this? |
|
Done #6927 |
Revert "Set-Location should use path with wildcard characters if it exists instead of globbing (PowerShell#5839)" This reverts commit 7459b54.
PR Summary
When InitialSessionState initializes it tries to SetLocation to current working directory,
but if the directory name contains PowerShell wildcard characters, it fails and reverts
to $PSHOME.
The change affects Set-Location in that if the path exists (even if containing wildcard characters), just use it.
Fix #5752
PR Checklist
Note: Please mark anything not applicable to this PR
NA.[feature]if the change is significant or affects feature testsWIP:to the beginning of the title and remove the prefix when the PR is ready.