Merge pull request #3479 from sinkuu/issue_2995

Fix indexing panic on unicode whitespaces
This commit is contained in:
Seiichi Uchida 2019-03-29 22:03:42 +09:00 committed by GitHub
commit f70ce00305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -651,7 +651,7 @@ pub fn get_comment_end(
if let Some(i) = block_open_index {
match post_snippet.find('/') {
Some(j) if j < i => block_open_index = None,
_ if i > 0 && &post_snippet[i - 1..i] == "/" => block_open_index = None,
_ if post_snippet[..i].chars().last() == Some('/') => block_open_index = None,
_ => (),
}
}
@ -692,8 +692,13 @@ pub fn has_extra_newline(post_snippet: &str, comment_end: usize) -> bool {
return false;
}
let len_last = post_snippet[..comment_end]
.chars()
.last()
.unwrap()
.len_utf8();
// Everything from the separator to the next item.
let test_snippet = &post_snippet[comment_end - 1..];
let test_snippet = &post_snippet[comment_end - len_last..];
let first_newline = test_snippet
.find('\n')
.unwrap_or_else(|| test_snippet.len());

View File

@ -0,0 +1,7 @@
fn issue_2995() {
// '\u{2028}' is inserted in the code below.
[0, 1];
[0, /* */ 1];
[0,1];
}

View File

@ -0,0 +1,7 @@
fn issue_2995() {
// '\u{2028}' is inserted in the code below.
[0, 1];
[0, /* */ 1];
[0, 1];
}