mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
* fix issue #559: to json -r serializes datetime without spaces * add in a third test which checks spaces in both keys and values * fix clippy error
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
use std::fmt::{Display, LowerExp};
|
||||
use std::io;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::num::FpCategory;
|
||||
|
||||
use super::error::{Error, ErrorCode, Result};
|
||||
@ -1032,7 +1033,20 @@ where
|
||||
T: ser::Serialize,
|
||||
{
|
||||
let vec = to_vec(value)?;
|
||||
let mut string = String::from_utf8(vec)?;
|
||||
string.retain(|c| !c.is_whitespace());
|
||||
let string = remove_json_whitespace(vec);
|
||||
Ok(string)
|
||||
}
|
||||
|
||||
fn remove_json_whitespace(v: Vec<u8>) -> String {
|
||||
let reader = BufReader::new(&v[..]);
|
||||
let mut output = String::new();
|
||||
for line in reader.lines() {
|
||||
match line {
|
||||
Ok(line) => output.push_str(line.trim().trim_end()),
|
||||
_ => {
|
||||
eprintln!("Error removing JSON whitespace");
|
||||
}
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
|
Reference in New Issue
Block a user