From 0b70ca8451a692404a3ca6ac5b0c072cd137c6c5 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 9 Aug 2022 07:58:36 -0500 Subject: [PATCH] escape single quotes and remove ansi escape sequences (#6271) * escape single quotes and remove ansi escape sequences prior to storing strings in db * clippy --- .../src/database/commands/into_sqlite.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/database/commands/into_sqlite.rs b/crates/nu-command/src/database/commands/into_sqlite.rs index 52b72232f..3a8fc2b99 100644 --- a/crates/nu-command/src/database/commands/into_sqlite.rs +++ b/crates/nu-command/src/database/commands/into_sqlite.rs @@ -140,7 +140,7 @@ fn action( }) .join(",") } - // Number is formats so keep them without quotes + // Number formats so keep them without quotes Value::Int { val: _, span: _ } | Value::Float { val: _, span: _ } | Value::Filesize { val: _, span: _ } @@ -246,7 +246,17 @@ fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String nu_value_to_string(val.to, ", ", config) ) } - Value::String { val, .. } => val, + Value::String { val, .. } => { + // don't store ansi escape sequences in the database + let stripped = { + match strip_ansi_escapes::strip(&val) { + Ok(item) => String::from_utf8(item).unwrap_or(val), + Err(_) => val, + } + }; + // escape single quotes + stripped.replace('\'', "''") + } Value::List { vals: val, .. } => val .iter() .map(|x| nu_value_to_string(x.clone(), ", ", config))