Skip to content

Rule Request: Warn Against Special Characters that PowerShell Accepts #1436

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

Open
cpmcgrath opened this issue Apr 7, 2020 · 6 comments
Open

Comments

@cpmcgrath
Copy link

Powershell 7 supports the use of Em Dash ( – ) for parameter prefixes, while Windows Powershell doesn't and can cause errors such as

Invoke-Command –ComputerName $Computer ...
–ComputerName $Computer
The string is missing the terminator: "

I'm not sure how but in the last month a good dozen Em Dashes were accidentally added to my codebase.

As Em Dashes are almost impossible to notice in a fix width font, I think it should be considered best practice to never use them and put a big error/warning on screen when you come across one.

@rjmholt
Copy link
Contributor

rjmholt commented Apr 7, 2020

This feature request is best suited to PSScriptAnalyzer, which provides the warnings for the PowerShell extension.

Just to clarify:

  • Windows PowerShell does support em-dashes, but only when it recognises the file's encoding (Notice that the particular reason it fails is because it also supports as an opening quote)
  • The em-dashes may always have been present and your file's encoding changed, or the can also be inserted when copy/pasting through things like MS Word
  • The actual underlying issue is that VSCode has encoded your file as UTF-8 without a BOM, but Windows PowerShell needs a BOM in order to not assume that the encoding is CP-1252. Take a look at the extensive encoding document we wrote to configure VSCode better to prevent this from happening in the future

@rjmholt rjmholt transferred this issue from PowerShell/vscode-powershell Apr 7, 2020
@ghost ghost added the Needs: Triage 🔍 label Apr 7, 2020
@bergmeister
Copy link
Collaborator

There is also this VS-Code extension for interactive linting: https://marketplace.visualstudio.com/items?itemName=nachocab.highlight-dodgy-characters

@rjmholt
Copy link
Contributor

rjmholt commented Apr 7, 2020

And I should also spruik UseBOMForUnicodeEncodedFile

@SydneyhSmith SydneyhSmith changed the title Warn against Em dash Rule Request: Warn Against Special Characters that PowerShell Accepts Apr 7, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Oct 19, 2020

@notgriffin
Copy link

Referencing #1880, there should also be a warning when any of the following unicode characters are used to quote a string: U+201C, U+201D, U+201F, U+2019, U+301D, U+301E, U+301F, U+FF02, U+201A, U+2018, U+201B, U+2758, or U+275C.

@iRon7
Copy link

iRon7 commented Aug 30, 2023

Just scanning for Rule Request in:title and apparently I created a duplicate (specifically for the em-dash in parameters), see: #1932

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

No branches or pull requests

6 participants