Fix multibyte codepoint crash (#1243)

Co-authored-by: Evan Richter <evanjrichter@gmail.com>
This commit is contained in:
Casey Rodarmor 2022-06-20 17:24:13 -07:00 committed by GitHub
parent 691b3dcf56
commit c625d61abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -5,7 +5,7 @@ pub fn unindent(text: &str) -> String {
let mut start = 0; let mut start = 0;
for (i, c) in text.char_indices() { for (i, c) in text.char_indices() {
if c == '\n' || i == text.len() - c.len_utf8() { if c == '\n' || i == text.len() - c.len_utf8() {
let end = i + 1; let end = i + c.len_utf8();
lines.push(&text[start..end]); lines.push(&text[start..end]);
start = end; start = end;
} }

View File

@ -57,6 +57,7 @@ mod invocation_directory;
mod json; mod json;
mod line_prefixes; mod line_prefixes;
mod misc; mod misc;
mod multibyte_char;
mod positional_arguments; mod positional_arguments;
mod quiet; mod quiet;
mod quote; mod quote;

6
tests/multibyte_char.rs Normal file
View File

@ -0,0 +1,6 @@
use super::*;
#[test]
fn bugfix() {
Test::new().justfile("foo:\nx := '''ǩ'''").run();
}