From f406f74591bd7acc8928a87efd3ab275be71664e Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 23 Oct 2023 23:13:31 -0400 Subject: [PATCH] Add a test for the double-escape bug --- src/responders/serde.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/responders/serde.rs b/src/responders/serde.rs index fd1eec1..bc05290 100644 --- a/src/responders/serde.rs +++ b/src/responders/serde.rs @@ -234,3 +234,28 @@ impl serde::Serialize for SwapOption { } } } + +#[cfg(test)] +mod tests { + use serde_json::json; + + use super::*; + + #[test] + fn valid_event_to_header_encoding() { + let evt = HxEvent::new_with_data( + "my-event", + json!({"level": "info", "message": { + "body": "This is a test message.", + "title": "Hello, world!", + }}), + ) + .unwrap(); + + let header_value = events_to_header_value(vec![evt]).unwrap(); + + let expected_value = r#"{"my-event":{"level":"info","message":{"body":"This is a test message.","title":"Hello, world!"}}}"#; + + assert_eq!(header_value, HeaderValue::from_static(expected_value)); + } +}