Skip to content

Commit a0b7503

Browse files
committed
test if string contains single-quote
1 parent 0b3d2c0 commit a0b7503

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

git2-hooks/src/hookspath.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,22 @@ impl HookPaths {
134134
);
135135
os_str.push(hook.replace('\'', REPLACEMENT));
136136
} else {
137-
os_str.push(hook.as_os_str()); // TODO: this doesn't work if `hook` contains single-quotes
137+
#[cfg(windows)]
138+
{
139+
use std::os::windows::ffi::OsStrExt;
140+
if hook
141+
.as_os_str()
142+
.encode_wide()
143+
.into_iter()
144+
.find(|x| *x == (b'\'' as u16))
145+
.is_some()
146+
{
147+
// TODO: escape single quotes instead of failing
148+
return Err(HooksError::PathToString);
149+
}
150+
}
151+
152+
os_str.push(hook.as_os_str());
138153
}
139154
os_str.push("'");
140155
os_str.push(" \"$@\"");

0 commit comments

Comments
 (0)