Reputation: 1517
const shell = require('electron').shell
shell.openExternal(path.join('base_path', 'child_path'))
If I join path like this in win,
the result of path.join('base_path', 'child_path') would be escaped and I can't open the link.
The separator(/) would be escaped.
I can open the link if I do like this.
shell.openExternal('base_path' + '/' + 'child_path')
But I think joining path like this could be dangerous.
Any way to solve this?
I want to use path.join().
Upvotes: 0
Views: 1288
Reputation: 18487
If I understand your question, the way I've solved this is to use the toUnix
method of the upath lib
upath.toUnix(upath.join(__dirname, "assets", "email.svg"));
Normal path doesn't convert paths to a unified format (ie /) before calculating paths (normalize, join), which can lead to numerous problems. Also path joining, normalization etc on the two formats is not consistent, depending on where it runs. Running path on Windows yields different results than when it runs on Linux / Mac.
In general, if you code your paths logic while developing on Unix/Mac and it runs on Windows, you may run into problems when using path.
Note that using Unix / on Windows works perfectly inside nodejs (and other languages), so there's no reason to stick to the Windows legacy at all.
Upvotes: 1