Skip to content

F5 uses double quotes around script's path to dot-source/run script (instead of single quotes) #4238

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

Closed
5 of 6 tasks
thegraffix opened this issue Nov 1, 2022 · 1 comment · Fixed by PowerShell/PowerShellEditorServices#1940
Assignees
Labels

Comments

@thegraffix
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

To be 100% honest, I don't know if this is a bug, a design choice or is outside the scope of the PS extension.

When pressing F5 to run a script, the PS VS Code extension uses double quotes around the script's path. This presents an issue if there is a $ anywhere in the path (e.g. C:\Scripts\Test$myScript\Get-ScriptPath.ps1) as variable expansion takes place when it shouldn't.

# Pressing F5 in VS Code uses double quotes around the script's path and breaks if the path name contains a $
PS C:\> . "c:\Scripts\Test$myScript\Get-ScriptPath.ps1"
.: The term 'c:\Scripts\Test\Get-ScriptPath.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.




# Dot-sourcing with manually added single quotes works
PS C:\> . 'c:\Scripts\Test$myScript\Get-ScriptPath.ps1'

This script's path is:  C:\Scripts\Test$myScript\Get-ScriptPath.ps1




# Tabbing/autocompleting a script's path works (in VS console, pwsh.exe and PowerShell.exe)
PS C:\> & 'C:\Scripts\Test$myScript\Get-ScriptPath.ps1'

This script's path is:  C:\Scripts\Test$myScript\Get-ScriptPath.ps1

Within the VS Code PS console, (or pwsh.exe or PowerShell.exe) if I tab/autocomplete a script's location, it will add the call operator & and automatically add single quotes around a path with spaces or a $.

PowerShell Version

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.7
PSEdition                      Core
GitCommitId                    7.2.7
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

PS C:\> code --version
1.72.2
d045a5eda657f4d7b676dedbfa7aab8207f8a075
x64

Extension Version

PS C:\> code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

In VS Code, press F5 to run a PowerShell script that's inside a folder containing a $ in the path name
(e.g. C:\Scripts\Test$myScript\Get-ScriptPath.ps1)

Visuals

No response

Logs

No response

@thegraffix thegraffix added the Issue-Bug A bug to squash. label Nov 1, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 1, 2022
@andyleejordan andyleejordan self-assigned this Nov 1, 2022
@andyleejordan andyleejordan added Area-Debugging and removed Needs: Triage Maintainer attention needed! labels Nov 2, 2022
@andyleejordan
Copy link
Member

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants