Hyper: Hyper breaks $PATH if path contains unicode

Created on 20 Jan 2020  Β·  17Comments  Β·  Source: vercel/hyper

  • [x] I am on the latest Hyper.app version
  • [x] I have searched the issues of this repo and believe that this is not a duplicate

  • OS version and name: Windows

  • Hyper.app version: 3.0.2
  • Link of a Gist with the contents of your .hyper.js: Irrevalant
  • Relevant information from devtools _(CMD+ALT+I on macOS, CTRL+SHIFT+I elsewhere)_: N/A
  • The issue is reproducible in vanilla Hyper.app: Is Vanilla

Issue

When Hyper append its own path on the PATH environment variable, it replaces the unicode characters in the path with question mark or οΏ½.

The path of the Hyper is unaffected, but this affects all other paths in $PATH.

High

Most helpful comment

@Stanzilla
I tried out native-reg Looks like the list needs to be updated

| Package | Read | Write | Comments
| --- | --- | --- | --- |
| node-winreg | ❌ | βœ”οΈ | Gives οΏ½ on reading unicode characters |
| windows-registry-node | ❌ | ❌ | Doesn't seem to run on newer Node versions |
| registry-js | βœ”οΈ | ❌ | Doesn't have write method |
| windows-native-registry | βœ”οΈ | ❌ | Writing unicode gives garbage |
| node-regedit | ❌ | βœ”οΈ | Expands env vars incorrectly while reading
| vscode-windows-registry | ❌ | ❌ | Gives � on reading unicode & doesn't have write method |
| native-reg | βœ”οΈ | βœ”οΈ | 😍|

native-reg reads and writes unicode correctly, expands env vars correctly, and also allows to get values without expanding.
I tested it on a separate script through Node. Will have to implement it for our code and check(hoping for no more issues).
Will send a pr when done.

All 17 comments

Thanks for pointing it out.
@Stanzilla I tried to pinpoint the issue, it seems to be caused by 'winreg' which we're using to access and edit the Registry to add to PATH.
Can be verified by running this↓ in node (will need to install winreg first, and some unicode chars should be there in PATH)

const Registry = require('winreg');
const envKey = new Registry({ hive: 'HKCU', key: '\\Environment' });
envKey.values((err, items) => {
    let item = items.find(i => i.name.toUpperCase() === 'PATH');
    console.log(item.value)
});

Here itself the unicode symbols come incorrect, which goes downstream and causes the issue.

winreg's last release was 3 years ago, We should try out some other packages for registry, which might help fix this.

https://github.com/CatalystCode/windows-registry-node maybe?

can you try it out? I tried to install it but I'm getting some node-gyp errors, From what I understood from the source repo, it doesn't seem to support newer node versions.
I tried out https://github.com/desktop/registry-js also, I'm able to read the registry values with Unicode correctly, but it doesn't seem to have a way of setting values.

Hrm, won't have that much time in the near future but will investigate further!

This issue is critical for all non-English Windows user. If someone who uses non-ASCII username installs Hyper, his/her computer will suddenly become buggy, in irreversible way.

Reference

As a workaround, I changed Windows system locale to UTF-8 and now it works as intended. The few problems are (1) this option is currently in beta, (2) it might be incompatible for old softwares.

@Stanzilla
I tried out node-regedit
it's able to read and write unicode values correctly
But if the key is of type REG_EXPAND_SZ (it is in my case atleast) it expands the environment variables in the value in system context, giving incorrect value. See https://github.com/ironSource/node-regedit/issues/40

man, why is there no lib for this that works properly :D

Here's a summary of all the packages I've tried

| Package | Read | Write | Comments
| --- | --- | --- | --- |
| node-winreg | ❌ | βœ”οΈ | Gives οΏ½ on reading unicode characters |
| windows-registry-node | ❌ | ❌ | Doesn't seem to run on newer Node versions |
| registry-js | βœ”οΈ | ❌ | Doesn't have write method |
| windows-native-registry | βœ”οΈ | ❌ | Writing unicode gives garbage |
| node-regedit | ❌ | βœ”οΈ | Expands env vars incorrectly while reading
| vscode-windows-registry | ❌ | ❌ | Gives � on reading unicode & doesn't have write method |

Looks like no single package can do both correctly

i really don't want to suggest using two libs, one for reading and one for writing but do we have a choice?

I searched a bit more on npm and these 2 seem worth trying
native-reg
node-winreg-utf8

How about using Iconv-lite for converting utf-8 to system locale? Although it would need to detect system locale...

@BasixKOR can you elaborate a bit please?
Like, how to get correct utf-8 values? A proof of concept would be awesome, if possible.

@Stanzilla
I tried out native-reg Looks like the list needs to be updated

| Package | Read | Write | Comments
| --- | --- | --- | --- |
| node-winreg | ❌ | βœ”οΈ | Gives οΏ½ on reading unicode characters |
| windows-registry-node | ❌ | ❌ | Doesn't seem to run on newer Node versions |
| registry-js | βœ”οΈ | ❌ | Doesn't have write method |
| windows-native-registry | βœ”οΈ | ❌ | Writing unicode gives garbage |
| node-regedit | ❌ | βœ”οΈ | Expands env vars incorrectly while reading
| vscode-windows-registry | ❌ | ❌ | Gives � on reading unicode & doesn't have write method |
| native-reg | βœ”οΈ | βœ”οΈ | 😍|

native-reg reads and writes unicode correctly, expands env vars correctly, and also allows to get values without expanding.
I tested it on a separate script through Node. Will have to implement it for our code and check(hoping for no more issues).
Will send a pr when done.

jesus, finally! great work!

yep
I feel like I can write a whole blog post on Registry modules for node now.

@Stanzilla @BasixKOR @simnalamburt
Can you all try out the build from the pr
Make sure to have some unicode string in your path, to check if it's working correctly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aem picture aem  Β·  3Comments

hxnt picture hxnt  Β·  3Comments

cilice picture cilice  Β·  3Comments

juicygoose picture juicygoose  Β·  3Comments

alejandrofloresm picture alejandrofloresm  Β·  3Comments