Fix silent removal of all quotes from input string

The CLI simply replaced all the quotes in the origin string which can
result in unexpected behavior. For example, consider the input string:
SET "all the cars' tyres" 'have holes'
In our last impl, we'd end up replacing all single and double quotes
resulting in the origin string being entirely changed! This commit
fixes this.
next
Sayan Nandan 3 years ago
parent 6cd3d4d2eb
commit 9f08122759

@ -31,6 +31,11 @@ All changes in this project will be noted in this file.
- Reduced memory usage in `sky-bench`
- Reduced allocations in Skyhash (`skyd`) protocol implementation
- Misc. fixes in internal structures (`skyd`)
- Improvements in printing of binary strings in `skysh`
### Fixes
- Fixed unexpected removal of single and double quotes from input strings in `skysh`
## Version 0.7.0

@ -65,7 +65,19 @@ macro_rules! option_unwrap_or {
pub fn split_into_args(q: &str) -> Vec<String> {
let args: Vec<String> = RE
.find_iter(q)
.map(|val| val.as_str().replace("'", "").replace("\"", ""))
.map(|val| {
let mut v = val.as_str();
let mut chars = v.chars();
let first = chars.nth(0);
let last = chars.last();
if let Some('"' | '\'') = first {
v = &v[1..];
}
if let Some('"' | '\'') = last {
v = &v[..v.len()];
}
v.to_owned()
})
.collect();
args
}

Loading…
Cancel
Save