Skip to content

Commit 7b4903b

Browse files
committed
correctly escape single-quote if utf8
1 parent 38a3484 commit 7b4903b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod tests {
8181
use crate::sync::tests::repo_init_with_prefix;
8282

8383
fn repo_init() -> Result<(TempDir, Repository)> {
84-
repo_init_with_prefix("gitui $# ")
84+
repo_init_with_prefix("gitui $# ' ")
8585
}
8686

8787
#[test]

git2-hooks/src/hookspath.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ impl HookPaths {
124124
let mut os_str = std::ffi::OsString::new();
125125
os_str.push("'");
126126
if let Some(hook) = hook.to_str() {
127-
os_str.push(hook.replace('\'', "\\'"));
127+
// SEE: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02
128+
// Enclosing characters in single-quotes ( '' ) shall preserve the literal value of each character within the single-quotes.
129+
// A single-quote cannot occur within single-quotes.
130+
const REPLACEMENT: &str = concat!(
131+
"'", // closing single-quote
132+
"\\'", // one escaped single-quote (outside of single-quotes)
133+
"'", // new single-quote
134+
);
135+
os_str.push(hook.replace('\'', REPLACEMENT));
128136
} else {
129137
os_str.push(hook.as_os_str()); // TODO: this doesn't work if `hook` contains single-quotes
130138
}

0 commit comments

Comments
 (0)