From c625d61abdd787af999b419fced6bec0adb4d7b8 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 20 Jun 2022 17:24:13 -0700 Subject: [PATCH] Fix multibyte codepoint crash (#1243) Co-authored-by: Evan Richter --- src/unindent.rs | 2 +- tests/lib.rs | 1 + tests/multibyte_char.rs | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/multibyte_char.rs diff --git a/src/unindent.rs b/src/unindent.rs index 4dcc566..cec9200 100644 --- a/src/unindent.rs +++ b/src/unindent.rs @@ -5,7 +5,7 @@ pub fn unindent(text: &str) -> String { let mut start = 0; for (i, c) in text.char_indices() { if c == '\n' || i == text.len() - c.len_utf8() { - let end = i + 1; + let end = i + c.len_utf8(); lines.push(&text[start..end]); start = end; } diff --git a/tests/lib.rs b/tests/lib.rs index f507679..0827bba 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -57,6 +57,7 @@ mod invocation_directory; mod json; mod line_prefixes; mod misc; +mod multibyte_char; mod positional_arguments; mod quiet; mod quote; diff --git a/tests/multibyte_char.rs b/tests/multibyte_char.rs new file mode 100644 index 0000000..2d65831 --- /dev/null +++ b/tests/multibyte_char.rs @@ -0,0 +1,6 @@ +use super::*; + +#[test] +fn bugfix() { + Test::new().justfile("foo:\nx := '''ǩ'''").run(); +}