Handle non-ascii character at boundary (#5089)

* Handle non-ascii character at boundary

* Replace substraction underflow check with early termination
This commit is contained in:
Stéphane Campinas 2022-02-02 02:06:14 +01:00 committed by GitHub
parent 8b0b213cdd
commit 368a9b7cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View File

@ -278,6 +278,9 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
}
cur_index
};
if max_width_index_in_input == 0 {
return SnippetState::EndOfInput(input.concat());
}
// Find the position in input for breaking the string
if line_end.is_empty()
@ -301,7 +304,7 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
return if trim_end {
SnippetState::LineEnd(input[..=url_index_end].concat(), index_plus_ws + 1)
} else {
return SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1);
SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1)
};
}

View File

@ -0,0 +1,22 @@
// rustfmt-wrap_comments: true
/// A comment to test special unicode characters on boundaries
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here this goes to the next line
fn main() {
if xxx {
let xxx = xxx
.into_iter()
.filter(|(xxx, xxx)| {
if let Some(x) = Some(1) {
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
// xxxxxxxxxx. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxx
// 是sdfadsdfxxxxxxxxxsdfaxxxxxx_xxxxx_masdfaonxxx
if false {
return true;
}
}
false
})
.collect();
}
}

View File

@ -0,0 +1,23 @@
// rustfmt-wrap_comments: true
/// A comment to test special unicode characters on boundaries
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here
/// this goes to the next line
fn main() {
if xxx {
let xxx = xxx
.into_iter()
.filter(|(xxx, xxx)| {
if let Some(x) = Some(1) {
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
// xxxxxxxxxx. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxx
// 是sdfadsdfxxxxxxxxxsdfaxxxxxx_xxxxx_masdfaonxxx
if false {
return true;
}
}
false
})
.collect();
}
}