Skip to content

Commit 9649e84

Browse files
committed
test if string contains single-quote
1 parent 48922ce commit 9649e84

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

git2-hooks/src/hookspath.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,22 @@ impl HookPaths {
146146
if let Some(hook) = hook.to_str() {
147147
os_str.push(hook.replace('\'', REPLACEMENT));
148148
} else {
149-
os_str.push(hook.as_os_str()); // TODO: this doesn't work if `hook` contains single-quotes
149+
#[cfg(windows)]
150+
{
151+
use std::os::windows::ffi::OsStrExt;
152+
if hook
153+
.as_os_str()
154+
.encode_wide()
155+
.into_iter()
156+
.find(|x| *x == (b'\'' as u16))
157+
.is_some()
158+
{
159+
// TODO: escape single quotes instead of failing
160+
return Err(HooksError::PathToString);
161+
}
162+
}
163+
164+
os_str.push(hook.as_os_str());
150165
}
151166
os_str.push("'");
152167
os_str.push(" \"$@\"");

0 commit comments

Comments
 (0)