Skip to content

Commit

Permalink
Use empty string in Sse event when there is no data
Browse files Browse the repository at this point in the history
Using an empty string instead of null
is what the classic rest client does,
so let's align with it

Closes: quarkusio#37033
  • Loading branch information
geoand committed Nov 13, 2023
1 parent 41e4ad1 commit 042aed2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public void testParser() {
testParser("data:foo\ndata:\ndata:bar\n\n", "foo\n\nbar", null, null, null, SseEvent.RECONNECT_NOT_SET);

// no data: no event
testParser("\n", null, null, null, null, SseEvent.RECONNECT_NOT_SET);
testParser("data:\n\n", null, null, null, null, SseEvent.RECONNECT_NOT_SET);
testParser("data\n\n", null, null, null, null, SseEvent.RECONNECT_NOT_SET);
testParser("\n", "", null, null, null, SseEvent.RECONNECT_NOT_SET);
testParser("data:\n\n", "", null, null, null, SseEvent.RECONNECT_NOT_SET);
testParser("data\n\n", "", null, null, null, SseEvent.RECONNECT_NOT_SET);

// all fields
testParser("data:DATA\nid:ID\n:COMMENT\nretry:23\nevent:NAME\n\n", "DATA", "COMMENT", "ID", "NAME", 23);
// all fields and no data
testParser("id:ID\n:COMMENT\nretry:23\nevent:NAME\n\n", null, "COMMENT", "ID", "NAME", 23);
testParser("id:ID\n:COMMENT\nretry:23\nevent:NAME\n\n", "", "COMMENT", "ID", "NAME", 23);

// optional space after colon
testParser("data:foo\n\n", "foo", null, null, null, SseEvent.RECONNECT_NOT_SET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void testSseForMultiWithOutboundSseEvent() throws InterruptedException {
});
sse.open();
Assertions.assertTrue(latch.await(20, TimeUnit.SECONDS));
org.assertj.core.api.Assertions.assertThat(results).containsExactly(null, "uno", "dos", "tres");
org.assertj.core.api.Assertions.assertThat(results).containsExactly("", "uno", "dos", "tres");
org.assertj.core.api.Assertions.assertThat(ids).containsExactly(null, "one", "two", "three");
org.assertj.core.api.Assertions.assertThat(names).containsExactly(null, "eins", "zwei", "drei");
org.assertj.core.api.Assertions.assertThat(comments).containsExactly("dummy", null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void dispatchEvent() {
event.setComment(commentBuffer.length() == 0 ? null : commentBuffer.toString());
// SSE spec says empty string is the default, but JAX-RS says null if not specified
event.setId(lastEventId);
event.setData(dataBuffer.length() == 0 ? null : dataBuffer.toString());
event.setData(dataBuffer.length() == 0 ? "" : dataBuffer.toString());
// SSE spec says "message" is the default, but JAX-RS says null if not specified
event.setName(eventType);
event.setReconnectDelay(eventReconnectTime);
Expand Down

0 comments on commit 042aed2

Please sign in to comment.