Skip to content

Commit

Permalink
Fixed issue on Windows where a space in a path could cause problems w…
Browse files Browse the repository at this point in the history
…ith specific programs.
  • Loading branch information
blemelin committed Sep 14, 2022
1 parent b20e01c commit 1ab9bc3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::{ffi::OsStr, io, os::windows::ffi::OsStrExt, ptr};
use std::{ffi::{OsStr,OsString}, io, os::windows::ffi::OsStrExt, ptr};

use std::os::raw::c_int;
use windows_sys::Win32::UI::Shell::ShellExecuteW;

use crate::IntoResult;

fn convert_path(path: &OsStr) -> io::Result<Vec<u16>> {
let mut maybe_result: Vec<_> = path.encode_wide().collect();
// Surround path with double quotes "" to handle spaces in path.
let mut quoted_path = OsString::with_capacity(path.len());
quoted_path.push("\"");
quoted_path.push(&path);
quoted_path.push("\"");

let mut maybe_result: Vec<_> = quoted_path.encode_wide().collect();
if maybe_result.iter().any(|&u| u == 0) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down

0 comments on commit 1ab9bc3

Please sign in to comment.