Skip to content

fix(conformance): allow optional space after SSE data: field name#285

Open
ethe wants to merge 1 commit into
durable-streams:mainfrom
ethe:fix/sse-data-field-space
Open

fix(conformance): allow optional space after SSE data: field name#285
ethe wants to merge 1 commit into
durable-streams:mainfrom
ethe:fix/sse-data-field-space

Conversation

@ethe
Copy link
Copy Markdown

@ethe ethe commented Mar 16, 2026

Several SSE-related conformance tests use regexes like data:({[^}]+}) and assertions like toContain("data:line1") that require no space after the data: field name. This causes false failures against servers that output data: value (with space after the colon).

The SSE specification explicitly states:

If value is not empty, and the first character of value is a U+0020 SPACE character, remove the first character from value.

Both data:hello and data: hello are valid and produce the identical value hello. Many HTTP frameworks (Axum, Actix, hyper, etc.) include the space by convention for readability.

The SSE specification (W3C Server-Sent Events) defines the data field
format as `data:VALUE` where if the first character after the colon is
a U+0020 SPACE, it is stripped. This means both `data:hello` and
`data: hello` are valid and produce the same value.

Several conformance test regexes used `data:({...})` which only matches
the no-space variant. This causes false failures against servers that
use `data: ` (with space), such as implementations built on Axum, Actix,
or other frameworks that follow the common convention of including a
space after the colon for readability.

Change all SSE data field regexes from `data:` to `data: ?` (optional
space) and text assertions from `toContain("data:line")` to
`toMatch(/data: ?line/)`.

Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 16, 2026

Deploy Preview for durable-streams-docs canceled.

Name Link
🔨 Latest commit 011ae1c
🔍 Latest deploy log https://app.netlify.com/projects/durable-streams-docs/deploys/69b813488c95260008c64cd0

Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data: ? change is the right fix per the WHATWG SSE spec, which allows an optional single space after the colon. However, the existing [^}]+ in the control match patterns (e.g., lines 1619 and 1717 in packages/server-conformance-tests/src/index.ts) remains fragile — it will silently fail to capture the full JSON payload if the control event data ever contains nested objects, since [^}] stops at the first closing brace. That's a pre-existing issue, but it's worth noting alongside this change since you're already touching these regex lines.

For the multiline data assertions around line 3419, switching from .toContain('data:line1') to .toMatch(/data: ?line1/) is correct, but consider whether a test case with exactly two spaces (data: line1) should be explicitly verified as non-conforming — the ? regex correctly rejects it, but there's no negative assertion to document that intent and catch a future regression if someone widens it to \s*.

@ethe
Copy link
Copy Markdown
Author

ethe commented Mar 31, 2026

hi @balegas (hope I'm asking the suitable person), could you please have a review?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants