Skip to content

Commit 9b8a87e

Browse files
committed
add test with invalid utf8
1 parent f58f550 commit 9b8a87e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,41 @@ pub fn hooks_prepare_commit_msg(
7474

7575
#[cfg(test)]
7676
mod tests {
77+
use std::ffi::{OsStr, OsString};
78+
7779
use git2::Repository;
7880
use tempfile::TempDir;
7981

8082
use super::*;
8183
use crate::sync::tests::repo_init_with_prefix;
8284

8385
fn repo_init() -> Result<(TempDir, Repository)> {
84-
repo_init_with_prefix("gitui $# ' ")
86+
const INVALID_UTF8: &[u8] = b"\xED\xA0\x80";
87+
let mut os_string: OsString = OsString::new();
88+
89+
os_string.push("gitui $# ' ");
90+
91+
#[cfg(windows)]
92+
{
93+
use std::os::windows::ffi::OsStringExt;
94+
95+
const INVALID_UTF8: &[u16] =
96+
INVALID_UTF8.map(|b| b as u16);
97+
98+
os_str.push(OsString::from_wide(INVALID_UTF8));
99+
100+
assert!(os_string.to_str().is_none());
101+
}
102+
#[cfg(unix)]
103+
{
104+
use std::os::unix::ffi::OsStrExt;
105+
106+
os_string.push(OsStr::from_bytes(INVALID_UTF8));
107+
108+
assert!(os_string.to_str().is_none());
109+
}
110+
111+
repo_init_with_prefix(os_string)
85112
}
86113

87114
#[test]

asyncgit/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub mod tests {
123123
};
124124
use crate::error::Result;
125125
use git2::Repository;
126-
use std::{path::Path, process::Command};
126+
use std::{ffi::OsStr, path::Path, process::Command};
127127
use tempfile::TempDir;
128128

129129
///
@@ -150,7 +150,7 @@ pub mod tests {
150150
///
151151
#[inline]
152152
pub fn repo_init_with_prefix(
153-
prefix: &'static str,
153+
prefix: impl AsRef<OsStr>,
154154
) -> Result<(TempDir, Repository)> {
155155
init_log();
156156

0 commit comments

Comments
 (0)