Skip to content
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

PowerShell unexpectedly executes documents located in $env:PATH directories as commands #12632

Closed
mklement0 opened this issue May 12, 2020 · 4 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@mklement0
Copy link
Contributor

mklement0 commented May 12, 2020

See also: #12625

Steps to reproduce

# Create a text file in the temp dir and prepend 
# the temp dir to $env:PATH for this session.
'hi' > temp:/foo.txt
$env:PATH = (Convert-Path 'temp:/') + [io.path]::PathSeparator + $env:PATH

# Go to a directory *other* than where the file is located (and where no foo.txt file exists either).
Set-Location

# Invoke foo.txt by mere file name.
{ foo.txt } | Should -Throw

Expected behavior

The test should succeed, because the following error should be reported:

foo.txt: The term 'foo.txt' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Actual behavior

foo.txt opens in the system's default text editor, and the test fails:

Expected an exception, to be thrown, but no exception was thrown.

That is, foo.txt was unexpectedly looked for in the directories listed in $env:PATH, and then invoked as a document, as if it had been passed to Invoke-Item.

I don't think users expect to invoke documents by mere file name from $env:PATH locations - doing so isn't useful, and, conversely, users may end up operating on different files than they expect.

Note that, by contrast, Invoke-Item foo.txt commendably looks only in the current directory.

Environment data

PowerShell Core 7.1.0-preview.2
@mklement0 mklement0 added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label May 12, 2020
@iSazonov iSazonov added the WG-Engine core PowerShell engine, interpreter, and runtime label Jan 16, 2021
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

2 participants