Skip to content

If you send a ServerEvent with '0' as data, it will not producte 'data: 0' #62151

@leonexcc

Description

@leonexcc

Symfony version(s) affected

7.3.4,main

Description

In

there is check with a simple if ($this->data) this will be false for '' and for '0'. That results in an empty event if you try to sent '0'.

Possible fix would be:

if (is_iterable($this->data)) {
    foreach ($this->data as $data) {
        yield \sprintf('data: %s', $data)."\n";
    }
} elseif ($this->data !== null || $this->data !== '') {
    yield \sprintf('data: %s', $this->data)."\n";
}

A possible workaround is to wrap the '0' in an array.

How to reproduce

$event = new ServerEvent('0');
foreach ($event as $line) {
    echo $line;
}

This should produce data: 0 but produces nothing

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions