Skip to content

Commit cb3b968

Browse files
author
Stephan Dilly
committed
fix cutting commit msg in between utf8 clusters (#188)
1 parent 7995519 commit cb3b968

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

asyncgit/src/sync/commits_info.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ pub fn get_message(
103103

104104
fn limit_str(s: &str, limit: usize) -> &str {
105105
if let Some(first) = s.lines().next() {
106-
&first[0..limit.min(first.len())]
106+
let mut limit = limit.min(first.len());
107+
while !first.is_char_boundary(limit) {
108+
limit += 1
109+
}
110+
&first[0..limit]
107111
} else {
108112
""
109113
}
@@ -112,7 +116,7 @@ fn limit_str(s: &str, limit: usize) -> &str {
112116
#[cfg(test)]
113117
mod tests {
114118

115-
use super::get_commits_info;
119+
use super::{get_commits_info, limit_str};
116120
use crate::error::Result;
117121
use crate::sync::{
118122
commit, stage_add_file, tests::repo_init_empty,
@@ -171,4 +175,9 @@ mod tests {
171175

172176
Ok(())
173177
}
178+
179+
#[test]
180+
fn test_limit_string_utf8() {
181+
assert_eq!(limit_str("里里", 1), "里");
182+
}
174183
}

0 commit comments

Comments
 (0)