Event::json_data
can construct an invalid SSE event by passing a serde_json::value::RawValue
#2981
Closed
1 task done
Bug Report
When using
Event::json_data
with aserde_json::value::RawValue
it is possible to construct an invalid SSE event.This happens because
RawValue
will also capture newlines between object entries as it only validates that the bytes are valid json.This means that the string
"{\n\"foo\":\"bar\"}"
when deserialized into aRawValue
and serialized withEvent::json_data
will not be parsed correctly as internally it gets written to the buffer usingserde_json::to_writer
.Reproduction
Looking at the output of
dbg!
of the bytes should be enough to see the issue but I thought I would verify it again using a SSE parsing lib.Solutions
serde_json::value::RawValue
could lead to invalid Events (easy)serde_json::to_string
instead and than call toEvent::data
which will split the newlines correctly into multiple data fields. (Slow)serde_json::to_writer
but wrap buffer in some custom writer which will skip newlines which should be fine as newlines are guaranteed to be escaped in json strings. (should be pretty fast still)I would be interested in making a PR for 3. if that is the desired solution.
The text was updated successfully, but these errors were encountered: