From 68a314b5cbddcdd20b006c9c99cc221445675208 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 27 Dec 2019 19:03:00 +1300 Subject: [PATCH 1/2] UTF8 fix for twitter-reported issue --- crates/nu-parser/src/parse/parser.rs | 5 ++++- tests/shell/mod.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/parse/parser.rs b/crates/nu-parser/src/parse/parser.rs index 78ae113d5..f1b9fc140 100644 --- a/crates/nu-parser/src/parse/parser.rs +++ b/crates/nu-parser/src/parse/parser.rs @@ -357,7 +357,10 @@ fn word<'a, T, U, V>( pub fn matches(cond: fn(char) -> bool) -> impl Fn(NomSpan) -> IResult + Copy { move |input: NomSpan| match input.iter_elements().next() { - Option::Some(c) if cond(c) => Ok((input.slice(1..), input.slice(0..1))), + Option::Some(c) if cond(c) => { + let len_utf8 = c.len_utf8(); + Ok((input.slice(len_utf8..), input.slice(0..len_utf8))) + } _ => Err(nom::Err::Error(nom::error::ParseError::from_error_kind( input, nom::error::ErrorKind::Many0, diff --git a/tests/shell/mod.rs b/tests/shell/mod.rs index 33ab1f98a..7626fefa0 100644 --- a/tests/shell/mod.rs +++ b/tests/shell/mod.rs @@ -29,6 +29,21 @@ mod pipeline { }) } + #[test] + fn doesnt_break_on_utf8_command() { + let actual = nu!( + cwd: std::path::PathBuf::from("."), + r#" + sh -c "echo ö" + "# + ); + + assert!( + actual.contains("ö"), + format!("'{}' should contain ö", actual) + ); + } + #[test] fn can_process_row_as_it_argument_to_an_external_command_given_the_it_data_is_one_string_line() { From 10368d7060f2837117f8319c461537a98e84a2f8 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 27 Dec 2019 19:25:44 +1300 Subject: [PATCH 2/2] UTF8 fix for twitter-reported issue --- tests/shell/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/shell/mod.rs b/tests/shell/mod.rs index 7626fefa0..ec8cec39f 100644 --- a/tests/shell/mod.rs +++ b/tests/shell/mod.rs @@ -32,11 +32,11 @@ mod pipeline { #[test] fn doesnt_break_on_utf8_command() { let actual = nu!( - cwd: std::path::PathBuf::from("."), + cwd: ".", pipeline( r#" - sh -c "echo ö" + echo ö "# - ); + )); assert!( actual.contains("ö"),