From 1ab9bc37a0fc04d9fa033245d0c44392f2a2912a Mon Sep 17 00:00:00 2001 From: Benjamin Lemelin Date: Wed, 14 Sep 2022 16:43:16 -0400 Subject: [PATCH] Fixed issue on Windows where a space in a path could cause problems with specific programs. --- src/windows.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 5ff175e..57298e4 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,4 +1,4 @@ -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; @@ -6,7 +6,13 @@ use windows_sys::Win32::UI::Shell::ShellExecuteW; use crate::IntoResult; fn convert_path(path: &OsStr) -> io::Result> { - 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,