File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,11 @@ pub fn get_message(
103
103
104
104
fn limit_str ( s : & str , limit : usize ) -> & str {
105
105
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]
107
111
} else {
108
112
""
109
113
}
@@ -112,7 +116,7 @@ fn limit_str(s: &str, limit: usize) -> &str {
112
116
#[ cfg( test) ]
113
117
mod tests {
114
118
115
- use super :: get_commits_info;
119
+ use super :: { get_commits_info, limit_str } ;
116
120
use crate :: error:: Result ;
117
121
use crate :: sync:: {
118
122
commit, stage_add_file, tests:: repo_init_empty,
@@ -171,4 +175,9 @@ mod tests {
171
175
172
176
Ok ( ( ) )
173
177
}
178
+
179
+ #[ test]
180
+ fn test_limit_string_utf8 ( ) {
181
+ assert_eq ! ( limit_str( "里里" , 1 ) , "里" ) ;
182
+ }
174
183
}
You can’t perform that action at this time.
0 commit comments