question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrated Console trims leading and trailing whitespace before executing commands, results in multiple PSReadLine HistoryItem's in the current session

See original GitHub issue

System 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:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
msftrncscommented, Feb 21, 2021

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:

# note there is a trailing space after the backtick on the next line!
$a = echo hello`  
$a | format-hex

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

                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 68 65 6C 6C 6F 20                               hello 

wrong (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`
0reactions
msftbot[bot]commented, Nov 6, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

about PSReadLine - PowerShell | Microsoft Learn
PSReadLine provides a powerful command-line editing experience for the PowerShell console. It provides: Syntax coloring of the command line; A ...
Read more >
Support/cmder_mini/vendor/conemu ... - PowerShell Gallery
than first console run duration. So, ConEmu was closed before second console process was created. * gh-943: Rename option to 'Change mouse cursor...
Read more >
WhatsNew ConEmu | PDF | Command Line Interface - Scribd
Command ConEmuC -ConInfo prints current console tech info. ... ConEmuArgs now contains only ConEmu.exe s switches (before -cmd or -cmdli
Read more >
Doing More with PSReadline History -- Part 2
As I mentioned in the first article, PSReadline persists command history across PowerShell sessions. These commands do not show when you run ......
Read more >
Trim a String in Windows PowerShell - Hosting Ultraso
Problem You want to remove leading or trailing spaces from a string or user input. Solution Use the Trim() method of the string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found