Skip to content

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

Closed
PowerShell/PowerShellEditorServices
#1940
@thegraffix

Description

@thegraffix

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

ms-vscode.powershell@2022.10.0

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions