php-http/message

Check if body is empty string in stream factories

Closed this issue · 4 comments

Q A
Bug? no
New Feature? yes

Actual Behavior

Currently the stream factories check whether the body is null, and only in that case they don't write to the stream.

Expected Behavior

Empty strings are not written to a stream.

Possible Solutions

Writting an empty string to the stream doesn't make any sense, so we should check that too.

👍

dbu commented

agreed. i propose we simply do a non-strict check if ($content) { write } (or if (!$content) {abort} if that makes more sense).

@dbu But you do not want to prevent writing when $content is a string containing only the character 0.

dbu commented

ups, very good point. so we need to be explicit with null === $content || '' === $content