Skip to content

ServerSentEventHttpMessageReader does not recognize data fields without a colon #37461

Open

Description

@margarita-sk

ServerSentEventHttpMessageReader does not recognize SSE data fields when the colon is omitted:

id:c42
event:foo
data
data

or

id:c42
event:foo
data

According to the WHATWG HTML specification, a line without a colon must be processed as a field name with an empty value.
Therefore, data and data: should be treated equivalently.

Reproducible test case:

    @Test
    void readServerSentEventsDataWithoutColon() {
        // given
        ServerSentEventHttpMessageReader reader = new ServerSentEventHttpMessageReader();
        String body = """
                id:c42
                event:foo
                data
                data
                """;
        MockServerHttpRequest request = MockServerHttpRequest.post("/")
                .body(body);

        // when
        Flux<ServerSentEvent> events = reader.read(ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class), request, Collections.emptyMap())
                .cast(ServerSentEvent.class);

        // then - fails
        StepVerifier.create(events)
                .expectNext(ServerSentEvent.builder()
                        .id("c42")
                        .event("foo")
                        .data("\n")
                        .build())
                .expectComplete()
                .verify();
    }

Expected behavior

The reader should follow the WHATWG SSE parsing algorithm:
data\ndata should produce an event with data("\n"), just like data:\ndata:

Actual behavior

The implementation only handles data fields that start with data:
data\ndata produce an event with data(null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions