Byron / open-rs

Open a path or URL with the system-defined program
http://byron.github.io/open-rs
MIT License
319 stars 49 forks source link

On Windows, path with spaces are not double quoted. #53

Closed blemelin closed 2 years ago

blemelin commented 2 years ago

Let's say we want to open this file with Visual Studio Code : D:\projects\work 5.txt.

open::with("D:\\projects\\work 5.txt", "code").unwrap();

Doing this ends up opening two files : work and 5.txt. For this to work properly, the path must be inside double quotes like this :

open::with("\"D:\\projects\\work 5.txt\"", "code").unwrap();

Is this the intended behaviour ? On other platforms, this crate seems to handle spaces perfectly fine, so I created a fix for Windows in a fork of this repository. I can open a Pull Request if you are interested. A lot of programs can open multiple files at the same time, but this crate seem to be intended to open one file at a time, hence this issue.

Byron commented 2 years ago

Thanks for letting me know, and a fix for this would be greatly appreciated.

This definitely isn't intended behaviour and I believe the difference in handling of arguments might be in the nature of windows programs, maybe. On linux, an argument passed to a program is just that, and it can contain any character including whitespace, no additional splitting is performed as it doesn't go through a shell. On windows, a single string is passed as concatenation of all arguments, as I understood it, which then is split by the program itself. Hence one will always have to escape certain characters to avoid the splitting from happening, which isn't done yet.

blemelin commented 2 years ago

I've created the requested pull request. See PR #54. Thanks a lot for your work. :smiley:

Byron commented 2 years ago

Thank you! The fix is now available in v3.0.3.