Skip to content

F5 with script containing single quotes results in 'not recognized as a ....' error #4269

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
6 tasks done
msftrncs opened this issue Nov 17, 2022 · 5 comments · Fixed by PowerShell/PowerShellEditorServices#1957
Assignees
Labels

Comments

@msftrncs
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

Following #4238, anytime an argument is quoted, it needs to have existing quotes escaped. On Windows, single quotes can appear in the file name/file path, but double quotes cannot, but on 'nix, both can.

I created a script with quotes in the file name (this is not at all unusual for me), added something simple to the script file, and then pressed F5 to attempt to run it, and received an error that the path was invalid.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19044
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

1.73.1
6261075646f055b99068d3688932416f2346dd3b
x64

Extension Version

Steps to Reproduce

Create script with single quotes and press F5 to run.

Visuals

image

Logs

No response

@msftrncs msftrncs added the Issue-Bug A bug to squash. label Nov 17, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 17, 2022
@andyleejordan
Copy link
Member

You'll need to escape the single quotes. We had to switch from double to single quotes to avoid interpolating $foo as a PowerShell variable, and single quotes is what PowerShell also uses when tab-completing so the semantics are more in line with PowerShell now.

@andyleejordan
Copy link
Member

Err, I guess with F5 we'll need to escape the single quotes.

@andyleejordan
Copy link
Member

@SeeminglyScience I swear we were running this through an escaper at one point?

@andyleejordan andyleejordan added Area-Debugging and removed Needs: Triage Maintainer attention needed! labels Nov 17, 2022
@msftrncs
Copy link
Author

Ideally PowerShell would provide an argument escaper, as it has one as part of the Completer, but I am not sure it has a public interface.

@andyleejordan
Copy link
Member

Ok so once upon a time we did run this through some amount of escaping per PowerShell/PowerShellEditorServices#1611. In fact, there's a comment that "For a saved file we just execute its path (after escaping it)." But we stopped escaping it! I think the course of action here is to continue to single-quote the file, so we don't have to escape anything except single quotes.

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