Skip to content

When we paste powershell script in VS code, space is getting replaced by  #1628

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

Closed
BipulRaman opened this issue Dec 5, 2018 · 4 comments
Closed

Comments

@BipulRaman
Copy link

Issue Type: Bug

Step1: Copy a woking powershell script
Step2: When we paste powershell script in VS code, space is getting replaced by Â
Note: It is not visible in editor, but during run, error is being thrown as syntex error. This issue is observed specially code is copied from a ps1 file which is copied from one VM to another by putting into ZIP file. This issue is not observed when we paste it in Powershell ISE. I am sharing the sample script here:
https://gist.github.com/BipulRaman/eb598cfaa75d9b077f0e18ba021346a5

 will not be visible in the editor, but when you will run the script, you will see exception. I am not able to reproduce the issue repeatedly, but i have captured screenshot for the same code in two different editor. Please have a look on attached screenshots.
powershell ise
vs code

VS Code version: Code 1.29.1 (bc24f98b5f70467bc689abf41cc5550ca637088e, 2018-11-15T19:13:36.375Z)
OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (8 x 2712)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 31.88GB (21.41GB free)
Process Argv D:\DevTest\Block.ps1
Screen Reader no
VM 0%
Extensions (10)
Extension Author (truncated) Version
xml Dot 2.3.2
Angular2 joh 7.0.1
python ms- 2018.11.0
cpptools ms- 0.20.1
csharp ms- 1.17.1
PowerShell ms- 1.9.0
typescript-javascript-grammar ms- 0.0.47
team ms- 1.144.1
debugger-for-chrome msj 4.11.1
LiveServer rit 5.3.1
@rjmholt
Copy link
Contributor

rjmholt commented Dec 5, 2018

Thanks for opening an issue @BipulRaman.

This is quite similar to #1308. Please have a read of that.

This is an encoding problem and you will need to ensure that your PowerShell and ISE encoding settings in the VM and host sessions, along with the VSCode encoding settings, are all synchronised.

On Windows, it's likely you are using either the CP-1252 codepage or UTF-16 but VSCode is using UTF-8. This page is quite helpful for debugging the problem.

Unfortunately, there is nothing we can do from the extension to work out what encoding bytes are coming from or going to; even if we could control copying and pasting (those things are in VSCode, not the PowerShell extension), trying to guess encodings and transforming inputs would break a lot more than it would fix. People trying to guess and transform encodings is part of the cause of this problem in the first place.

@rjmholt rjmholt closed this as completed Dec 5, 2018
@rjmholt
Copy link
Contributor

rjmholt commented Dec 5, 2018

If you look at the debug page I linked above, it looks like there might be a non-breaking space hidden in your script.

The best way to debug this is going to be:

  • Verify the encoding settings in the ISE, VSCode, and both PowerShell runtimes
  • Print out the script as hex bytes (Format-Hex helps here)
  • Compare the output on host and VM

My general advice in these cross-encoding scenarios is to stick to ASCII characters only. Strip out any bytes above 0x7f in the script file.

@rjmholt
Copy link
Contributor

rjmholt commented Dec 6, 2018

@BipulRaman did you manage to find a fix for this issue? Have a look through the issues in this repo for encoding. This one might help: #1306 (comment).

@rjmholt
Copy link
Contributor

rjmholt commented Dec 6, 2018

Also #1351

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

No branches or pull requests

2 participants