Integrated Console trims leading and trailing whitespace before executing commands, results in multiple PSReadLine HistoryItem's in the current session
See original GitHub issueSystem Details
Extenion: Preview 2020.9.0 (and stable 2020.6.0) System Details Output
### VSCode extensions:
dbaeumer.jshint@0.11.0
dbaeumer.vscode-eslint@2.1.14
docsmsft.docs-markdown@0.2.82
donjayamanne.githistory@0.6.14
eamodio.gitlens@11.2.1
fireside21.cshtml-tm@1.0.0
GitHub.vscode-pull-request-github@0.23.1
keroc.hex-fmt@1.0.0
ms-dotnettools.csharp@1.23.9
ms-edgedevtools.vscode-edge-devtools@1.1.3
ms-mssql.mssql@1.10.1
ms-vscode.hexeditor@1.4.0
ms-vscode.powershell@2020.6.0
ms-vscode.powershell-preview@2020.9.0
ms-vscode.Theme-TomorrowKit@0.1.4
msjsdiag.debugger-for-edge@1.0.15
Serhioromano.vscode-st@9.9.9
vscode.theme-monokai-less-dimmed@0.0.1
### PSES version: 2.3.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 7.1.2
PSEdition Core
GitCommitId 7.1.2
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Description
Revised 2021-02-21 as the scope of the issue become larger.
If a command is entered in to the integrated console with leading and/or trailing whitespace, the whitespace is trimmed before the command is executed. Then, recalling command history shows two nearly identical commands, the most recent with the whitespace trimmed, and the next recent with the original whitespace.
I originally found this with multiline commands where the last line was blank. This was of no real consequence, other than the result of the command history having two entries. However getting a better understanding, I’ve realized this applies to all whitespace, and trailing whitespace may actually be of importance and should not be removed.
If the following commands are entered one at a time, they will result in different output in the integrated console than they will in a normal PowerShell session.
# note there is a trailing space after the backtick on the next line!
$a = echo hello`
$a | format-hex
Correct result:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 68 65 6C 6C 6F 20 hello
Incorrect result (integrated console):
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 68 65 6C 6C 6F 60 hello`
This also affects using the <kbd>F8</kbd> (Run Selection) command. If the selection contains intentional trailing whitespace, it will be removed. However this will not result in two command history entries.
There are three separate but related issues:
- console input commands are trimmed of leading and trailing whitespace which is not the normal console behavior
- console input commands are added to the command history system twice, once by PSReadLine when the command line is returned, and again by the integrated console just after getting it from PSReadLine.
- commands/scripts not console input (ie: <kbd>F8</kbd>) are also trimmed of leading and trailing whitespace, which may cause unexpected results since it is not consistent with normal console behavior nor with script file execution behavior.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
I am pretty sure PSReadLine does not trim trailing white space, as the issue only occurs in the Integrated Console, and not in regular PowerShell console instances, and likewise the only place the trimming is happening is in the integrated console.
As a side issue, observe the output of the following script on both the integrated console and a regular (not integrated) powershell session:
If these lines are pasted 1 at a time in to integrated console, the hex output will be missing the space (Edit: actually it will have a backtick instead of a space) following the word
hello
. If they are pasted together, the space will be present. A regular powershell session will have the same result either way the commands are entered.correct
wrong (integrated console)
This issue was closed automatically as author feedback was indicated as needed, but there has been no activity in over a week. Please feel free to reopen with any available information!