escape single quotes and remove ansi escape sequences (#6271)

* escape single quotes and remove ansi escape sequences prior to storing strings in db

* clippy
This commit is contained in:
Darren Schroeder 2022-08-09 07:58:36 -05:00 committed by GitHub
parent 555d9ee763
commit 0b70ca8451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))