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

Non-Latin Characters Garbled #132

Open
cawoodm opened this issue Feb 14, 2021 · 4 comments
Open

Non-Latin Characters Garbled #132

cawoodm opened this issue Feb 14, 2021 · 4 comments

Comments

@cawoodm
Copy link

cawoodm commented Feb 14, 2021

It seems characters like ä or ü are incorrectly encoded in the resulting javascript string.

PowerShell Script foo.ps1

echo "bär"

Node-PowerShell

let PS = require('node-powershell');
const ps = new PS({
  executionPolicy: 'Bypass',
  noProfile: true
});
// ps.addCommand('echo bär'); // This works fine
ps.addCommand('./foo.ps1');
ps.invoke()
.then(output => {
  console.log(output);
})

Result:

bär

As you can see the buffer is mangled to bär:

<Buffer 62 c3 83 c2 a4 72>
b: 62 (OK)
ä: c3 83 c2 a4 (garbled)
r: 72 OK

At the utils.js level we see the UTF-8 Replacement characters:

239  191 189
EF   BF  BD => UTF Replacement Character
@cawoodm
Copy link
Author

cawoodm commented Feb 14, 2021

Apparently PowerShell is receiving ä encoded as 5 bytes 226 148 156 195 and 177!

ps.addCommand('$str="bär";echo $str; echo $([System.Text.Encoding]::UTF8.GetBytes($str))');
...
bär
98  
226 
148 
156 
195
177
114

@thomas3577
Copy link

thomas3577 commented Jun 19, 2022

@cawoodm Hi, do you have a solution or workaround for this problem yet? In the latest version, the problem is still present.

@cawoodm
Copy link
Author

cawoodm commented Jun 20, 2022

Nope, I gave up on this library 🤷‍♂️ and went for node-powershell.

https://github.com/cawoodm/powowshell/blob/master/ide/package.json

@thomas3577
Copy link

thomas3577 commented Jun 30, 2022

@cawoodm I am using node-powershell v5.0.1. And I am not familiar with using profiles for PowerShell. But now I was able to solve my problem by removing noProfile from PS-Config. But I'm not sure that's a good idea.

Anyway, "Bär" is now displayed as a "Bär" and no longer as "B├ñr". :-)

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