From 1e15f26e98ffaeccd7bb4ca6e3377ff484ef0744 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 29 Jul 2021 19:07:34 -0500 Subject: [PATCH] fix interpolated strings when using unicode (#3866) * fix interpolated strings when using unicode * added test case --- crates/nu-parser/src/parse.rs | 2 +- tests/shell/pipeline/commands/internal.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index f194bb1fa..1a8096625 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -650,7 +650,7 @@ fn parse_interpolated_string( scope: &dyn ParserScope, ) -> (SpannedExpression, Option) { trace!("Parse_interpolated_string"); - let string_len = lite_arg.item.len(); + let string_len = lite_arg.item.chars().count(); let inner_string = lite_arg .item .chars() diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 70162924f..789b5d9e7 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -215,6 +215,19 @@ fn string_interpolation_and_paren() { assert_eq!(actual.out, "a paren is ("); } +#[test] +fn string_interpolation_with_unicode() { + //カ = U+30AB : KATAKANA LETTER KA + let actual = nu!( + cwd: ".", + r#" + $"カ" + "# + ); + + assert_eq!(actual.out, "カ"); +} + #[test] fn bignum_large_integer() { let actual = nu!(