microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.74k stars 8.2k forks source link

Wrong character when pasting into Windows Terminal with a Windows Subsystem for Linux profile #12072

Open HasEveryUsernameBeenTaken opened 2 years ago

HasEveryUsernameBeenTaken commented 2 years ago

Windows Terminal version

1.11.3471.0

Windows build number

10.0.19044.0

Other Software

Windows Subsystem for Linux (version 2) Debian 5.10.60.1 (according to [Environment]::OSVersion in PowerShell inside WSL) PowerShell 7.2.1 (in Debian)

Steps to reproduce

First the case that I seem to be able to reproduce the easiest.

  1. First the general Windows Subsystem for Linux that's a bit hard to reproduce.

  2. Have Windows Subsystem for Linux installed and install Debian from the Windows store.

  3. Use the profile in Windows Terminal to open a command prompt for the WSL Debian machine.

  4. In Windows Terminal, have a hotkey for paste (such as CTRL+v or Shift+Insert) that's handled by Windows Terminal instead of the command line session.

  5. Install PowerShell using the instructions at https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.2 .

  6. In the PowerShell profile (in my case, ~/.config/powershell/Microsoft.PowerShell_profile.ps1), put the following:

# Register an event when PowerShell is closing cleanly to save the current
# history.
#
# Note:  Closing PowerShell via the X button may not allow this to save.  But,
# typing "exit" should work.
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action {
    # Save-PSHistory

    # Check if any jobs are still running.
    If (Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'}) {
        Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'} | Wait-Job
    }

    # If we have Linux "sync", run it.
    #
    # For now, we'll only call sync if it's '/bin/sync'.  Add a delay just in case it doesn't run.
    If (Test-Path -Path '/bin/sync') {
        If (Get-Command -Type Application '/bin/sync') {
            & /bin/sync
        }
    }

    Start-Sleep -Seconds 2
}
  1. In a text editor, such as Notepad, put many Box Drawings Double Horizontal characters ("═", Unicode character 0x2550). In my case, I had 80 (═══════════════════════════════════════════════════════════════════════════════).

  2. In Windows Terminal, start a Debian session, and start PowerShell with "pwsh".

  3. Copy the line of Box Drawings Double Horizontal characters, not including any newline characters.

  4. Paste them into the Debian session in Windows Terminal via CTRL+v shortcut.

It has occurred for me in Bash, but it's not consistent. I've only had it happen a few times by pressing and holding CTRL+v to paste the text many times.

Expected Behavior

The same text that was copied should be pasted into the command prompt.

Actual Behavior

I see "═" (Unicode character 0x2550) and "�" (Unicode character 0xFFFD) pasted.

From my Windows Terminal:

PS /home/cdenn/.config> '════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������'
════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
237dmitry commented 2 years ago

I think that the problem is different code pages in Linux and Windows. Try to set UTF8 as default windows locale ( intl.cpl )

elsaco commented 2 years ago

@HasEveryUsernameBeenTaken couldn't repro on windows terminal version 1.12.3472.0 (preview), Ubuntu on WSL2 and copy/paste from step 7. The only weird observation is that the thick line in the top one while yours is the bottom:

wt_bug_12072

What is the output of locale in Debian? Here's the Ubuntu output:

PS /home/tux> locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=
HasEveryUsernameBeenTaken commented 2 years ago

@elsaco,

On my Windows 10, I have Debian in WSL 2 and Ubuntu in WSL 1.

 PS cdenn@PORRE (2021-12-31 10:41) ~/Documents $ wsl --list --verbose
  NAME      STATE           VERSION
* Debian    Running         2
  Ubuntu    Running         1

The paste issue does seem to occur far less for me in Ubuntu than in Debian whether I use the PowerShell profile or not. But, it does happen for me. In this case, I renamed my PowerShell profile directory, so the it should be an empty profile. I then pressed and held CTRL+v for a while in Windows Terminal.

image

In Ubuntu, the locale is as follows:

PS /home/cdenn/.config> locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=
PS /home/cdenn/.config>

In Debian, the locale was different.

  bash cdenn@Porre-Debian (2021-12-31 10:12) ~ $ cat /etc/default/locale
#  File generated by update-locale
LC_ALL=C
LANGUAGE=en_US.UTF-8
  bash cdenn@Porre-Debian (2021-12-31 10:12) ~ $ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

I updated my Debian by modifying /etc/defaults/locale to match Ubuntu

LANG=C.UTF-8

and verified that Debian's locale matched.

  bash cdenn@Porre-Debian (2021-12-31 10:59) ~/.config $ locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=

In Debian, the issue still occurred immediately with the PowerShell profile in place:

  bash cdenn@Porre-Debian (2021-12-31 11:05) ~/.config/powershell $ ls
Microsoft.PowerShell_profile.ps1
  bash cdenn@Porre-Debian (2021-12-31 11:05) ~/.config/powershell $ cat Microsoft.PowerShell_profile.ps1
# Register an event when PowerShell is closing cleanly to save the current
# history.
#
# Note:  Closing PowerShell via the X button may not allow this to save.  But,
# typing "exit" should work.
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action {
        # Save-PSHistory

        # Check if any jobs are still running.
        If (Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'}) {
                Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'} | Wait-Job
        }

        # If we have Linux "sync", run it.
        #
        # For now, we'll only call sync if it's '/bin/sync'.  Add a delay just in case it doesn't run.
        If (Test-Path -Path '/bin/sync') {
                If (Get-Command -Type Application '/bin/sync') {
                        & /bin/sync
                }
        }

        Start-Sleep -Seconds 2
}
  bash cdenn@Porre-Debian (2021-12-31 11:05) ~/.config/powershell $ pwsh
PS /home/cdenn/.config/powershell> '════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������'
════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

When I tried again in Debian with an empty PowerShell profile, I did not experience the issue in a screen's worth of pasting, unlike what happened in Ubuntu. image

HasEveryUsernameBeenTaken commented 2 years ago

@237dmitry,

I wasn't exactly sure what option you were referring to set the default Windows locale. After opening intl.cpl, I went to the Administrative tab > Language for non-Unicode programs > Clicked the Change system locale button and saw a checkbox labeled "Beta: Use Unicode UTF-8 for worldwide language support". I enabled that and rebooted my Windows 10 computer. If you meant something else, please let me know.

After rebooting, the issue still occurred for me in Debian. Like what occurred when I replied to elsaco, I couldn't reproduce the issue with an empty PowerShell profile in WSL Debian.

image

However, it still occurred with the profile in place.

image

Here are the current locale settings within WSL Debian:

  bash cdenn@Porre-Debian (2021-12-31 11:44) ~/.config $ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
  bash cdenn@Porre-Debian (2021-12-31 11:44) ~/.config $ cat /etc/default/locale
#  File generated by update-locale
LC_ALL=C
LANGUAGE=en_US.UTF-8

# LANG=C.UTF-8

When I accessed my WSL Ubuntu machine, the pasting issue was less consistent, but it did occur within a few screens worth of holding CTRL+v.

elsaco commented 2 years ago

@HasEveryUsernameBeenTaken after adding your prompt the issue manifested on the 2nd paste:

wt_bug_12072_take2

237dmitry commented 2 years ago

If you meant something else, please let me know.

This is exactly what I suggested.

However, it still occurred with the profile in place.

It's hard to say anything. Especially without enabled wsl. My assumption was based on the interaction between Windows and Linux at the script portability level (with minor OS-oriented changes). Windows and Linux on different computers.

elsaco commented 2 years ago

This issue pops up also when Ubuntu is run outside windows terminal.

Custom prompt enabled: wt_paste_custom_prompt

Custom prompt disabled: wt_paste_no_custom_prompt

237dmitry commented 2 years ago

Custom prompt disabled

See your custom prompt. May be there is unclosed esc-sequence or may be something else.

HasEveryUsernameBeenTaken commented 2 years ago

@237dmitry,

Custom prompt disabled

See your custom prompt. May be there is unclosed esc-sequence or may be something else.

I'm pretty sure that the custom prompt that I use in Bash doesn't have a unclosed escape sequence, but I checked. The custom prompt that I use in PowerShell doesn't directly use escape sequences (such as "Write-Host -NoNewline -ForegroundColor Green").

In cmd.exe

C:\>wsl --list --verbose
  NAME      STATE           VERSION
* Debian    Stopped         2
  Ubuntu    Stopped         1

C:\>wsl --unregister Debian
Unregistering...

Verify that the files and vhdx are gone and reinstall Debian.

C:\>tree "C:\Users\cdenn\AppData\Local\Packages\TheDebianProject.DebianGNULinux_****"
Folder PATH listing
Volume serial number is ****
C:\USERS\CDENN\APPDATA\LOCAL\PACKAGES\THEDEBIANPROJECT.DEBIANGNULINUX_****
├───AC
│   └───Temp
├───AppData
├───LocalCache
│   ├───Local
│   │   └───Microsoft
│   └───Roaming
│       └───Microsoft
│           └───Windows
│               └───Start Menu
│                   └───Programs
├───LocalState
├───RoamingState
├───Settings
├───SystemAppData
│   └───Helium
└───TempState

C:\>wsl --list --verbose
  NAME      STATE           VERSION
* Ubuntu    Stopped         1

C:\>wsl --set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
The operation completed successfully.

C:\>wsl --install --distribution Debian
Debian GNU/Linux is already installed.
Launching Debian GNU/Linux...

In Debian default launch command prompt, do basic admin setup for this testing environment.

test@Porre:~$ sudo bash
root@Porre:/home/test# sudo echo "test ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99-myNoPassword
root@Porre:/home/test# echo "[network]" > /etc/wsl.conf
root@Porre:/home/test# echo "hostname = DebianTest" >> /etc/wsl.conf
root@Porre:/home/test# echo "generateHosts = true" >> /etc/wsl.conf
root@Porre:/home/test# cat /etc/wsl.conf
[network]
hostname = DebianTest
generateHosts = true
root@Porre:/home/test# exit

Verify that the old home directory from the previous Debian installation is gone.

test@Porre:~$ cd ..
test@Porre:/home$ ls -al
total 12
drwxr-xr-x  3 root root 4096 Jan  3 09:30 .
drwxr-xr-x 22 root root 4096 Jan  3 09:30 ..
drwxr-xr-x  2 test test 4096 Jan  3 09:30 test
test@Porre:/home$ sudo ls -al
total 12
drwxr-xr-x  3 root root 4096 Jan  3 09:30 .
drwxr-xr-x 22 root root 4096 Jan  3 09:30 ..
drwxr-xr-x  2 test test 4096 Jan  3 09:30 test

Close out the Debian command prompt window.

In cmd.exe, verify it's shutdown.

C:\>wsl --list --verbose
  NAME      STATE           VERSION
* Ubuntu    Stopped         1
  Debian    Stopped         2

Launch Debian in Windows Terminal.

test@DebianTest:~$ sudo apt update

...

test@DebianTest:~$ sudo apt upgrade

...

test@DebianTest:~$ wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
-bash: wget: command not found
test@DebianTest:~$ sudo apt install wget

...

test@DebianTest:~$ wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
--2022-01-03 09:53:43--  https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 13.82.67.141
Connecting to packages.microsoft.com (packages.microsoft.com)|13.82.67.141|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3124 (3.1K) [application/octet-stream]
Saving to: ‘packages-microsoft-prod.deb’

packages-microsoft-prod.deb                          100%[=====================================================================================================================>]   3.05K  --.-KB/s    in 0s

2022-01-03 09:53:44 (181 MB/s) - ‘packages-microsoft-prod.deb’ saved [3124/3124]

test@DebianTest:~$ sudo dpkg -i packages-microsoft-prod.deb
Selecting previously unselected package packages-microsoft-prod.
(Reading database ... 10421 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-debian10.1) ...
Setting up packages-microsoft-prod (1.0-debian10.1) ...
test@DebianTest:~$ sudo apt-get update
Get:1 https://packages.microsoft.com/debian/10/prod buster InRelease [29.8 kB]
Hit:2 http://ftp.debian.org/debian bullseye-backports InRelease
Hit:3 http://deb.debian.org/debian bullseye InRelease
Hit:4 http://security.debian.org/debian-security bullseye-security InRelease
Hit:5 http://deb.debian.org/debian bullseye-updates InRelease
Get:6 https://packages.microsoft.com/debian/10/prod buster/main armhf Packages [20.4 kB]
Get:7 https://packages.microsoft.com/debian/10/prod buster/main arm64 Packages [20.7 kB]
Get:8 https://packages.microsoft.com/debian/10/prod buster/main all Packages [3,847 B]
Get:9 https://packages.microsoft.com/debian/10/prod buster/main amd64 Packages [140 kB]
Fetched 214 kB in 1s (281 kB/s)
Reading package lists... Done
test@DebianTest:~$ sudo apt-get install -y powershell
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libicu67
The following NEW packages will be installed:
  libicu67 powershell
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 78.3 MB of archives.
After this operation, 227 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 libicu67 amd64 67.1-7 [8,622 kB]
Get:2 https://packages.microsoft.com/debian/10/prod buster/main amd64 powershell amd64 7.2.1-1.deb [69.7 MB]
Fetched 78.3 MB in 28s (2,752 kB/s)
Selecting previously unselected package libicu67:amd64.
(Reading database ... 10429 files and directories currently installed.)
Preparing to unpack .../libicu67_67.1-7_amd64.deb ...
Unpacking libicu67:amd64 (67.1-7) ...
Selecting previously unselected package powershell.
Preparing to unpack .../powershell_7.2.1-1.deb_amd64.deb ...
Unpacking powershell (7.2.1-1.deb) ...
Setting up libicu67:amd64 (67.1-7) ...
Setting up powershell (7.2.1-1.deb) ...
Processing triggers for libc-bin (2.31-13+deb11u2) ...
ldconfig: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

test@DebianTest:~$ pwsh
PowerShell 7.2.1
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /home/test> # First Test
PS /home/test> '═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════'

... Printed correctly ...

PS /home/test> exit
test@DebianTest:~$ mkdir -p .config/powershell
test@DebianTest:~$ cd .config/powershell/
test@DebianTest:~/.config/powershell$ nano Microsoft.PowerShell_profile.ps1
test@DebianTest:~/.config/powershell$ cat Microsoft.PowerShell_profile.ps1
# Register an event when PowerShell is closing cleanly to save the current
# history.
#
# Note:  Closing PowerShell via the X button may not allow this to save.  But,
# typing "exit" should work.
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action {
        # Save-PSHistory

        # Check if any jobs are still running.
        If (Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'}) {
                Get-Job -State Running | Where-Object {$PSItem.Name -iNe 'PowerShell.Exiting'} | Wait-Job
        }

        # If we have Linux "sync", run it.
        #
        # For now, we'll only call sync if it's '/bin/sync'.  Add a delay just in case it doesn't run.
        If (Test-Path -Path '/bin/sync') {
                If (Get-Command -Type Application '/bin/sync') {
                        & /bin/sync
                }
        }

        Start-Sleep -Seconds 2
}

test@DebianTest:~$ cd ~
test@DebianTest:~$ pwsh
PowerShell 7.2.1
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /home/test> # Second Test
PS /home/test> '════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������'
════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
PS /home/test> # Third Test
PS /home/test> '════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������'
════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

So yes, I'm convinced that any escaped sequences that I might normally use in a custom prompt are not causing this issue.

I've also simplified the PowerShell profile script to an empty event.

PS /home/test> exit
test@DebianTest:~$ nano .config/powershell/Microsoft.PowerShell_profile.ps1
test@DebianTest:~$ cat .config/powershell/Microsoft.PowerShell_profile.ps1
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action {
}
test@DebianTest:~$
test@DebianTest:~$ pwsh
PowerShell 7.2.1
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /home/test> '════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������'
════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
eabase commented 2 years ago

I would like to know what character is actually under the question marks... Note that Unicode =/= UTF-8|16

https://stackoverflow.com/questions/643694/what-is-the-difference-between-utf-8-and-unicode https://stackoverflow.com/questions/5290182/how-many-bytes-does-one-unicode-character-take

echo -en '═�'| xxd -g 1
00000000: e2 95 90 ef bf bd

Maybe an issue with even/odd number of .

echo -en "══"| iconv -f UTF-16LE -t UNICODEFFFE
══

echo -en "═══"| iconv -f UTF-16LE -t UNICODEFFFE
══▒
HasEveryUsernameBeenTaken commented 2 years ago

@eabase,

I would like to know what character is actually under the question marks... Note that Unicode =/= UTF-8|16

https://stackoverflow.com/questions/643694/what-is-the-difference-between-utf-8-and-unicode

echo -en '═�'| xxd -g 1
00000000: e2 95 90 ef bf bd

Maybe an issue with even/odd number of .

echo -en "══"| iconv -f UTF-16LE -t UNICODEFFFE
══

echo -en "═══"| iconv -f UTF-16LE -t UNICODEFFFE
══▒

My original report of the characters being Unicode character 0xFFFD was based on copying the character from Windows Terminal and pasting into the Microsoft Windows port of GNU Emacs and using M-x describe-character.

  1. Here is a sample of xxd output when pasting 80 characters.
    
    PS /home/test> /bin/echo -en '════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' | xxd -g 1
    00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 e2 95 90 e2  ................
    00000010: 95 90 e2 95 90 e2 95 90 e2 95 90 e2 95 90 e2 95  ................
    00000020: 90 e2 95 90 e2 95 90 e2 95 90 e2 95 90 e2 95 90  ................
    00000030: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000040: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000050: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000060: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000070: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000080: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000090: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    000000a0: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    000000b0: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    000000c0: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    000000d0: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    000000e0: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    000000f0: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000100: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000110: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000120: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000130: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000140: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000150: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000160: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000170: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000180: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000190: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    000001a0: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    000001b0: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    000001c0: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    000001d0: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    000001e0: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    000001f0: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000200: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000210: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000220: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000230: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000240: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef  ................
    00000250: bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf  ................
    00000260: bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd  ................
    00000270: 0a                                               .

2. I've not seen it consistently occur for a small number of characters.

PS /home/test> /bin/echo -en '══' ══ PS /home/test> /bin/echo -en '═══' ═══


To check the even versus odd case, here is a sample using 114 characters:

PS /home/test> /bin/echo -en '114 ════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' | iconv -f UTF-16LE -t UNICODEFFFE /usr/bin/iconv: failed to start conversion processing PS /home/test> /bin/echo -en '════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' | iconv -f UTF-16LE -t UNICODEFFFE /usr/bin/iconv: failed to start conversion processing


And here is a sample using 113 characters:

PS /home/test> /bin/echo -en '113 ════════════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' | iconv -f UTF-16LE -t UNICODEFFFE /usr/bin/iconv: failed to start conversion processing PS /home/test> /bin/echo -en '════════���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' | iconv -f UTF-16LE -t UNICODEFFFE /usr/bin/iconv: failed to start conversion processing


Yes, the 113 attempt without the number had more characters appearing.

3. I'm not currently able to reproduce this issue consistently outside of using Microsoft PowerShell.  I _believe_ it has occurred outside of PowerShell in Bash and Nano, but I wasn't able to produce the issue when using vim today in a Windows Subsystem for Linux 2 Debian environment.  

/bin/echo -en '══════════════════════════════════════════════════════════════════════════════════════════════������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������' > Debian-pwsh-bin_echo.bin

I have attached the results of this as "Debian-vim-manually_hold_paste.bin". [Debian-vim-manually_hold_paste.zip](https://github.com/microsoft/terminal/files/7808379/Debian-vim-manually_hold_paste.zip)
4. As I can easily reproduce this in PowerShell in a Windows Subsystem for Linux 2 Debian environment, I have used /bin/echo there to write the file "Debian-pwsh-bin_echo.bin".  [Debian-pwsh-bin_echo.zip](https://github.com/microsoft/terminal/files/7808377/Debian-pwsh-bin_echo.zip)

5. Here is a copy of the text when I viewed "Debian-pwsh-bin_echo.bin" using hexedit in my Windows Subsystem for Linux 2 Debian environment.

00000000 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 ............................................ 0000002C 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 ............................................ 00000058 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 ............................................ 00000084 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 ............................................ 000000B0 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 ............................................ 000000DC 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 ............................................ 00000108 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF ............................................ 00000134 BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF ............................................ 00000160 BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD ............................................ 0000018C EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF ............................................ 000001B8 BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF ............................................ 000001E4 BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD ............................................ 00000210 EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF ............................................ 0000023C BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF ............................................ 00000268 BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD ............................................ 00000294 EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF ............................................ 000002C0 BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF ............................................ 000002EC BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD ............................................ 00000318 EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF ............................................ 00000344 BD EF BF BD 0A ..... 00000370 0000039C 000003C8 000003F4 00000420 0000044C 00000478 000004A4 000004D0 000004CF 00000528 00000554 00000580 000005AC 000005D8 00000604 00000630 0000065C 00000688 000006B4 000006E0 0000070C 00000738 00000764 00000790 000007BC 000007E8 00000814 00000840 0000086C 00000898 000008C4 000008F0 0000091C --- Debian-pwsh-bin_echo.bin --0x0/0x349--0%---------------------------------------------------------------------------------------------------------------------------------------------------



6. I've also included the results of "Get-History | Export-Clixml -Path Debian-pwsh-History.xml" for what is recorded as PowerShell's history. [Debian-pwsh-History.zip](https://github.com/microsoft/terminal/files/7808378/Debian-pwsh-History.zip)
eabase commented 2 years ago

@HasEveryUsernameBeenTaken Because U+2550 is a 3-byte Unicode character, you will probably get different results depending if you copy/paste mod 3 times. So try to ensure that you copy exactly 1,2,3 or 4 characters at the time, then try pasting it different amount of times, and keep track of what you do. If this is all ok, then it may be a buffer issue. I noticed I pasted one of the long lines above and ended up with > 20kB which is close to clipboard/terminal buffer size, depending on implementation.

PS. the iconv -f UTF-16LE -t UNICODEFFFE was just an example, of showing how the number of characters encoded, gets distorted when converted/printing in odd numbers and mixing code sets. This is probably not the character set you are using.

HasEveryUsernameBeenTaken commented 2 years ago

@HasEveryUsernameBeenTaken Because U+2550 is a 3-byte Unicode character, you will probably get different results depending if you copy/paste mod 3 times. So try to ensure that you copy exactly 1,2,3 or 4 characters at the time, then try pasting it different amount of times, and keep track of what you do. If this is all ok, then it may be a buffer issue. I noticed I pasted one of the long lines above and ended up with > 20kB which is close to clipboard/terminal buffer size, depending on implementation.

PS. the iconv -f UTF-16LE -t UNICODEFFFE was just an example, of showing how the number of characters encoded, gets distorted when converted/printing in odd numbers and mixing code sets. This is probably not the character set you are using.

In pasting four characters at a single time, I only saw the corrupted characters once. It seemed more consistent with 10 characters.

PS /home/test> '════'
════
PS /home/test> '═══'
═══
PS /home/test> '══'
══
PS /home/test> '═'
═
PS /home/test> # Repeated 4 character pastes.
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> ════
════: The term '════' 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.
PS /home/test> ════
════: The term '════' 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.
PS /home/test> ������������
������������: The term '������������' 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.
PS /home/test> # There's one
PS /home/test> '════
>> '
════

PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════'
════
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '' | xxd -g 1
00000000: 0a                                               .
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '' | xxd -g 1
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> /bin/echo -en '════' | xxd -g 1
00000000: e2 95 90 e2 95 90 e2 95 90 e2 95 90 0a           .............
PS /home/test> # Try tripling
PS /home/test> '════════������������'
════════������������
PS /home/test> '═════════'
═════════
PS /home/test> '══════'
══════
PS /home/test> '═══'
═══
PS /home/test> # Try pasting 4 characters three times
PS /home/test> '════════════'
════════════
PS /home/test> '════════════'
════════════
PS /home/test> '════════════'
════════════
PS /home/test> # Press and hold pasting 4 characters at a time.
PS /home/test> '════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════'
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
PS /home/test> # Press and hold pasting 3 characters at a time.
PS /home/test> '════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════'
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
PS /home/test> # Press and hold pasting 2 characters at a time.
PS /home/test> '════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════'
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
PS /home/test> # Pasting 12 characters at a time.
PS /home/test> '════════������������'
════════������������
PS /home/test> # Pasting 11 characters at a time.
PS /home/test> '═══════════'
═══════════
PS /home/test> # Pasting 10 characters at a time.
PS /home/test> '════════������'
════════������
PS /home/test> # Pasting 9 characters at a time.
PS /home/test> '═════════'
═════════
PS /home/test> # Pasting 8 characters at a time.
PS /home/test> '════════'
════════
PS /home/test> # Pasting 7 characters at a time.
PS /home/test> '═══════'
═══════
PS /home/test> # Pasting 6 characters at a time.
PS /home/test> '══════'
══════
PS /home/test> # Pasting 5 characters at a time.
PS /home/test> '═════'
═════
PS /home/test>

The minimum amount of characters that I could get to semi-consistently get corrupted was 10 characters. But, it was not every time.

PS /home/test> # Single paste 10 characters again.
PS /home/test> '════════������'
════════������
PS /home/test> '════════������'
════════������
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> '══════════'
══════════
PS /home/test> '══════════'
══════════
PS /home/test> '══════════'
══════════
PS /home/test> '══════════'
══════════
PS /home/test> '══════════'
══════════
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> '══════════'
══════════
PS /home/test> '════════������'
════════������
PS /home/test> '══════════'
══════════
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> ══════════
══════════: The term '══════════' 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.
PS /home/test> ������������������������������
������������������������������: The term '������������������������������' 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.

Yes, that last line of corrupted characters was from a single paste.

image

eryksun commented 2 years ago

The console doesn't support reading input as UTF-8, so WSL actually reads UTF-16 from the console via low-level ReadConsoleInputW(), or at least it effectively makes that call. You can see this by debugging the conhost instance with a breakpoint set on ReadConsoleInputWImpl(). OTOH, writing to console output supports UTF-8, so WSL echoes the input back to the console screen buffer via WriteConsoleA(). That's apparent with a breakpoint set on WriteConsoleImplA().

I installed PowerShell in WSL to check this. I was able to reproduce the decoding problem with the replacement characters (U+FFFD) a couple of times, but I didn't capture the sequence of writes in those cases. I did capture the following sequence of writes from PowerShell in the case of echoing pasted "═══" (i.e. UTF-8 "\xe2\x95\x90" 3 times) to the screen:

1b 5b 3f 32 35 6c                           .[?25l
1b 5b 31 3b 31 39 48                        .[1;19H
1b 5b 39 33 6d e2 95 90                     .[93m...

1b 5b 33 39 3b 34 39 6d                     .[39;49m
1b 5b 30 6d                                 .[0m
1b 5b 31 3b 32 30 48                        .[1;20H
1b 5b 3f 31 32 6c 1b 5b 3f 32 35 68         .[?12l.[?25h
1b 5b 3f 32 35 6c                           .[?25l
1b 5b 31 3b 31 39 48                        .[1;19H
1b 5b 39 33 6d e2 95 90 e2 95 90            .[93m......

1b 5b 33 39 3b 34 39 6d                     .[39;49m
1b 5b 30 6d                                 .[0m
1b 5b 31 3b 32 31 48                        .[1;21H
1b 5b 3f 31 32 6c 1b 5b 3f 32 35 68         .[?12l.[?25h
1b 5b 3f 32 35 6c                           .[?25l
1b 5b 31 3b 31 39 48                        .[1;19H
1b 5b 39 33 6d e2 95 90 e2 95 90 e2 95 90   .[93m.........

1b 5b 33 39 3b 34 39 6d                     .[39;49m
1b 5b 30 6d                                 .[0m
1b 5b 31 3b 32 32 48                        .[1;22H
1b 5b 3f 31 32 6c 1b 5b 3f 32 35 68         .[?12l.[?25h

Each line is from a WriteConsoleImplA() call, with the debugger attached to conhost. This shows how the UTF-8 text sequence gets split over multiple VT sequences that are used to position the cursor, hide and show the cursor, set the foreground color, etc. It's not apparent to me why it prints one character, then two more, and then prints all three. Does this pattern of writes reduce visible flicker?

For a few releases, WriteConsoleA() has supported splitting a UTF-8 character sequence across 2-4 writes. But I wonder what happens if a UTF-8 character sequence gets split by a VT sequence. That could be the cause of the problem.

237dmitry commented 2 years ago

Windows 11, UTF-8, copying and pasting without problem. Then pasting the esc-sequences were lost in clipboard.

ss-20220104225556

eryksun commented 2 years ago

The decoding problem that displays replacement characters (U+FFFD) only occurs for me in Linux PowerShell under WSL when I repeatedly paste ══════════ fast enough such that the paste occurs before the prompt has finished displaying. At least for me, it never occurs if I wait a second between pastes.

eabase commented 2 years ago

@eryksun

The console doesn't support reading input as UTF-8, so WSL actually reads UTF-16 from the console via low-level

What do you mean there exactly? If my system is set to use UTF-8 and I "type" UTF-8 characters into console, are they converted into UTF-16 or are they assumed to be already in UTF-16? If coverted, then, when are they converted, immediately as I type, or when it's copied, or when it's pasted?

eabase commented 2 years ago

@237dmitry I was reproducing your lines from above (in Windows Terminal 1.11.3471.0, on Win10) and noticed that after having run the colored lines, there are pixel artifacts left behind:

image

They come and go, depending on how fast I scroll up and down. If I scroll fast they disappear, if I scroll slow, they stay.

BTW. What is ss -w doing?

237dmitry commented 2 years ago

They come and go, depending on how fast I scroll up and down. If I scroll fast they disappear, if I scroll slow, they stay.

I do not know what these artifacts are. Judging by the screenshot, this is the part of the 0x2550 symbols that the text on the left did not paint over.

BTW. What is ss -w doing?

This is script to make screenshot )) Just emulating of hotkeys Alt+PrtSc or PrtSc and saving. I did not find scrot for Windows.

elsaco commented 2 years ago

@237dmitry if scripted, like your loop, there's no corruption observed:

wt_bug_12072_take2

The only time I'm experiencing it is when using paste. Even then only when pasting sequentially. If I hold down ctrl+v there's no corruption. Here's a screenshot with 5-6 seq. paste then keys held down:

wt_bug_12072_take1

eryksun commented 2 years ago

If my system is set to use UTF-8 and I "type" UTF-8 characters into console, are they converted into UTF-16 or are they assumed to be already in UTF-16?

When you type in a window, the window procedure gets WM_KEYDOWN and WM_KEYUP messages that contain virtual key codes. These key codes are typically translated to UTF-16 WM_CHAR messages. For a paste, an app such as Terminal likely gets the clipboard text as UTF-16 via GetClipboardData(CF_UNICODETEXT).

For a ConPTY host such as a terminal, text input has to be encoded to UTF-8 and sent over a pipe to the console host (i.e. conhost or openconsole). But apparently the console host still uses UTF-16 internally for the input buffer. If you try to read the input buffer as UTF-8 via SetConsoleCP(CP_UTF8) and ReadFile(), ReadConsoleA(), or ReadConsoleInputA(), the console simply replaces each non-ASCII character (i.e. code points above 0x7F) with a null byte.

Anyway, this bug doesn't appear to be a problem with what Linux PowerShell reads from the terminal, but rather what it echoes back. The echoed text is UTF-8, at least until it gets to the console host. If it gets decoded to UTF-16 in the console host, then splitting a character sequence across multiple writes is potentially a problem. I thought that problem was resolved by internal buffering in the console. There could still be a problem with overlapped writes, when a partial sequence gets mistakenly completed by an unrelated write.

DHowett commented 2 years ago

Anyway, this bug doesn't appear to be a problem with what Linux PowerShell reads from the terminal, but rather what it echoes back.

Given that there's only one client connected (wsl, in this case) I don't believe it's an overlapping write issue. It really just seems like PSReadline horking it... since it's where all input is received and echoed in PowerShell.

eryksun commented 2 years ago

Given that there's only one client connected (wsl, in this case) I don't believe it's an overlapping write issue. It really just seems like PSReadline horking it... since it's where all input is received and echoed in PowerShell.

For me it's not related to PSReadLine:

PS /> remove-module psreadline
PS /> ĀaကbĀcကd
ĀaကbĀcကd: The term 'ĀaကbĀcကd' 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.
PS /> ��a���b��c���d

I can't reproduce the problem in the same ways as HasEveryUsernameBeenTaken. It turns out that it works fine for me if I paste the text in quotes. The problem only occurs with a rapid follow-up paste after the error message. It only affects non-ASCII characters. A replacement character (U+FFFD) is written for each non-ASCII byte in the UTF-8 string. It appears that something has tried to decode the UTF-8 sequence one byte at a time.

elsaco commented 2 years ago

It gets worse after unloading PSReadLine module:

wt_bug_12072_psreadline_removed

KarlAustin commented 1 year ago

I have a similar issue with Ubuntu under WSL2, but only after the terminal has been open for a period of time. Pasted data gets prefixed with: 0~ and suffixed with ~