xml escape

This commit is contained in:
Alex Auvolat 2020-04-24 18:56:00 +00:00
parent 91b2d1fcc1
commit a52db67954

View File

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::fmt::Write;
use std::sync::Arc;
use chrono::{DateTime, NaiveDateTime, Utc, SecondsFormat};
use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc};
use hyper::Response;
use garage_util::error::Error;
@ -99,7 +99,7 @@ pub async fn handle_list(
let last_modif = DateTime::<Utc>::from_utc(last_modif, Utc);
let last_modif = last_modif.to_rfc3339_opts(SecondsFormat::Millis, true);
writeln!(&mut xml, "\t<Contents>").unwrap();
writeln!(&mut xml, "\t\t<Key>{}</Key>", key).unwrap();
writeln!(&mut xml, "\t\t<Key>{}</Key>", xml_escape(key)).unwrap();
writeln!(&mut xml, "\t\t<LastModified>{}</LastModified>", last_modif).unwrap();
writeln!(&mut xml, "\t\t<Size>{}</Size>", info.size).unwrap();
writeln!(&mut xml, "\t\t<StorageClass>STANDARD</StorageClass>").unwrap();
@ -110,3 +110,9 @@ pub async fn handle_list(
Ok(Response::new(Box::new(BytesBody::from(xml.into_bytes()))))
}
fn xml_escape(s: &str) -> String {
s.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
}