From 6cedc05384c52f8e5c25f81353355f16c157a2cf Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Fri, 14 Apr 2023 18:53:14 +0200 Subject: [PATCH] Fix span of multibyte short flags (#8866) # Description Follow up to #8849 Work for #8821 Should unblock work on #8808 Missing is a restriction to printables or identifiers according to [UAX31](https://www.unicode.org/reports/tr31/) # User-Facing Changes Non ASCII characters should be allowed in shortflags. # Tests + Formatting Want to add some tests for the error reporting cases --- crates/nu-parser/src/parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index bc82f6f726..6235c2f05a 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -457,12 +457,12 @@ fn parse_short_flags( let short_flags = &arg_contents_uft8_ref[1..]; let mut found_short_flags = vec![]; let mut unmatched_short_flags = vec![]; - for short_flag in short_flags.chars().enumerate() { + for short_flag in short_flags.char_indices() { let short_flag_char = short_flag.1; let orig = arg_span; let short_flag_span = Span::new( orig.start + 1 + short_flag.0, - orig.start + 1 + short_flag.0 + 1, + orig.start + 1 + short_flag.0 + short_flag_char.len_utf8(), ); if let Some(flag) = sig.get_short_flag(short_flag_char) { // If we require an arg and are in a batch of short flags, error