Skip to content

HTMX4 SSE parser trims all leading whitespace instead of a single space #3588

@antonlorani

Description

@antonlorani

The SSE parser in htmx 4 currently removes all leading whitespace from field values. According to the SSE spec, only one leading space may be removed, and only if it exists.

Relevant code:

let value = line.slice(colonIndex + 1).trimStart();

Spec reference:
https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation

Collect the characters on the line after the first U+003A COLON character (:), and let value be that string. If value starts with a U+0020 SPACE character, remove it from value.

Example

Given this SSE payload:

id: 45
event:  message
data:  Hello, World!

Current behavior:

id = "45"
event = "message"
data = "Hello, World!"

Expected behavior (per spec):

id = "45"
event = " message"
data = " Hello, World!"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions