Skip to content
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

Weird control characters when pasting from windows clipboard to WSL2 #18579

Open
0anton opened this issue Feb 15, 2025 · 5 comments
Open

Weird control characters when pasting from windows clipboard to WSL2 #18579

0anton opened this issue Feb 15, 2025 · 5 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting

Comments

@0anton
Copy link

0anton commented Feb 15, 2025

Windows Terminal version

1.23.10353.0

Windows build number

10.0.19045.0

Other Software

cat, vim 9.0 (inside WSL2)

Steps to reproduce

Since recent time I encounter weird control character pasted before my actuall text, when I try to paste by clipboard into WSL terminal. It is reproduceable in vim and with simple cut:

Notice this unexpected characters ^[ at the beginning of the string:

 $ cat > test-file.json
^[{
  "pubsub_msg": "\"{\\\"kind\\\": \\\"storage#object\\\", \\\"id\\\":

cat > test-file.json

Right-mouse paste works fine, no extra characted is inserted:

[{
  "pubsub_msg[{
": "\"{\\\"kind\\\": \\\"storage#object\\\", 

The behavior is both reproduceable with Ctrl-V and with Ctrl-Shift-V.

I tried to follow the advice of #10572 and put into .inputrc lines:

set enable-bracketed-paste off

but it does not help...

The problem only appears in Windows Terminal, but not in wsl.exe for example.

The problem does not affect other shells, like PowerShell or CMD.EXE.

Interestingly, if the content is not formatted like hello world, it is being pasted withtout weird control character:

$ cat > /dev/null

hello world

Does anybody knows what is this problem?
It is very annoying to manually remove this characters from vim buffers manually after every paste...

@0anton 0anton added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Feb 15, 2025
@0anton
Copy link
Author

0anton commented Feb 16, 2025

Interestingly, the .inputrc's set enable-bracketed-paste 0 still works in normal release:

Windows Terminal
Version: 1.21.10351.0

But has not effect in preview:

Windows Terminal Preview
Version: 1.23.10353.0

So, I "fixed" it for myself by reverting from the preview back to normal.
Still want to discuss it, before the problem hits the stable channel.

UPDATE

Unfortunately above settings only fixes pastes to vim (WSL2), but not pastes to cat (readline?)
So, it is still an issue to me...

@carlos-zamora
Copy link
Member

carlos-zamora commented Feb 19, 2025

Thanks for filing! Can you reproduce the issue with Debug Tap enabled and share the output /? Instructions for how to use Debug tap can be found here: https://github.com/microsoft/terminal/wiki/Troubleshooting-Tips#enabling-the-debug-tap

This should help us debug this issue further 😊

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Feb 19, 2025
@0anton
Copy link
Author

0anton commented Feb 21, 2025

@carlos-zamora thanks for suggesting! cool troubleshooting method! I hope it will help to understand a problem.

So, I prepared a simple json string { "a": 1 } and pasting it to vim buffer and to cut stdin:

  1. Paste to vim -> correct
d057039:~$ vi a <Enter><Ctrl+V>
{ "a": 1 }

Key logger:

~␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␛[m"a"␣[New]␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣0,0-1␣␣␣␣␣␣␣␣␣All␣␛[1;3H␛[13;28;13;0;32;1_␛[73;23;105;1;32;1_␛[?25l␛[1m␛[80;1H--␣INSERT␣--␛[22m␛[36C0,1␣␣␣␣␣␣␣␣␣␣␣All␣␛[1;3H␛[?25h␛[73;23;105;0;32;1_␛[17;29;0;1;40;1_␛[200~{␣"a":␣1␣}␛[201~{␣"a":␣1␣}␛[?25l␛[46m␛[1;3H{␛[8C}␛[m␛[80;49H1,11␛[1;13H␛[?25h␛[86;47;22;0;40;1_␛[17;29;0;0;32;1_␛[O
  1. Paste to cat stdin -> incorrect - enters ^[ instead of {:
d057039:~$ cat > /dev/null <Enter><Ctrl+V>
^[ "a": 1 }

Key logger:

␛[K␍␊
␛[K␛[1;12H␛[?25h␛[76;38;12;0;40;1_␛[17;29;0;0;32;1_␛[38;72;0;1;288;1_cat␣>␣/dev/null␛[38;72;0;0;288;1_␛[13;28;13;1;32;1_␍␊
␛[13;28;13;0;32;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_␛[17;29;0;1;40;1_{␣"a":␣1␣}^[␣"a":␣1␣}␛[86;47;22;0;40;1_␛[17;29;0;0;32;1_␛[O

Now the same test in the same WSL2 console but using

Windows Terminal Preview
Version: 1.23.10353.0
d057039:~$ vi a <Enter><Ctrl+V>
^[ "a": 1 }

Logger:

␛[m␛[80;49H0,0-1␛[9CAll␛[1;3H␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?12$p␛[?12;2$y␛[?25l␛[?25h␛[?25l␛[?25h␛[13;28;13;0;32;1_␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[?25l␛[?25h␛[73;23;105;1;32;1_␛[?25l␛[80;1H␛[1m--␣INSERT␣--␛[m␛[80;49H␛[K␛[80;49H0,1␛[11CAll␛[1;3H␛[?25h␛[73;23;105;0;32;1_␛[17;29;0;1;40;1_␛[200~{␣"a":␣1␣}␛[201~␛[?25l␛[38;5;81m^[␛[m␣"a":␣1␣}␛[?25h␛[?25l␛[80;49H1,11-12␛[1;14H␛[?25h␛[17;29;0;0;32;1_␛[86;47;118;0;32;1_␛[O

As you can see the VIM is broken here (exactly same WSL2 terminal as above)

wsl2.exe provides clean input (right mouse paste)

disabling bracketed paste does not work:

$ bind 'set enable-bracketed-paste off'
d057039:~$ cat > /dev/null
^[ "a": 1 }^C

what could be the reason?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Feb 21, 2025
@DHowett
Copy link
Member

DHowett commented Feb 21, 2025

Thanks for capturing those! I'm surprised to see that the data is getting yeeted into the input buffer correctly.

␛[17;29;0;1;40;1_␛[200~{␣"a":␣1␣}␛[201~
[Ctrl Down]      BP+   Content   BP-

Would you mind pasting into showkey -a inside WSL2? It should be in the kbd package (Debian, Ubuntu) or your distribution's equivalent.

I suspect the issue will end up being somewhere in the unchartable middle, in one of our console app API translation layers.

@0anton
Copy link
Author

0anton commented Feb 21, 2025

@DHowett hope it helps, see below. I've been using Windows Terminals without this weird paste issue.

$ showkey -a

Press any keys - Ctrl-D will terminate this program                                                                                                                                                                                                                                                                     ^["a": 1}        27 0033 0x1b
         34 0042 0x22
         97 0141 0x61
         34 0042 0x22
         58 0072 0x3a
         32 0040 0x20
         49 0061 0x31
        125 0175 0x7d

Be aware that above the pasted input is for some reason only correctly shown in the edit mode, I'm cutting it out separately:

^["a": 1}        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting
Projects
None yet
Development

No branches or pull requests

3 participants