From 5254a6450d9f69f2ff23f5f7372d616db453708e Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Sat, 17 Feb 2024 11:54:59 +1300 Subject: [PATCH] Fix: escape content when converting Event to json [needs a further performance tweak] --- src/types/event/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/types/event/mod.rs b/src/types/event/mod.rs index 5efc91a..87db855 100644 --- a/src/types/event/mod.rs +++ b/src/types/event/mod.rs @@ -118,7 +118,13 @@ impl<'a> Event<'a> { output.extend(br#","tags":"#); output.extend(self.tags()?.as_json()); output.extend(br#","content":""#); - output.extend(self.content()); + // FIXME: we cannot just extend with the raw content, we have to + // json_escape it first. + // BUT unfortunately that currently requires a malloc. We will fix + // that in the next commit + let mut escaped_content = vec![0; self.content().len() * 2]; + let content_outlen = json_escape(self.content(), &mut escaped_content[..])?; + output.extend(&escaped_content[..content_outlen]); output.extend(br#"","sig":""#); let pos = output.len(); output.resize(pos + 128, 0);