-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Description
Symfony version(s) affected
All current versions
Description
When using DataPartFile with a wrong path (file does not exists) and then calling ->getBody()
it returns an empty string instead of an error.
How to reproduce
(new DataPartFile('/some/wrong/path/to/file.md'))->getBody() === ''; // true
.
Possible Solution
It is because Symfony does not use strict types. When calling file_get_contents
in this code :
public function getBody(): string
{
if ($this->body instanceof File) {
return file_get_contents($this->body->getPath());
}
if (null === $this->seekable) {
return $this->body;
}
if ($this->seekable) {
rewind($this->body);
}
return stream_get_contents($this->body) ?: '';
}
It automatically converts the false
to ''
.
Maybe wirth checking if false then throw throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
like in __construct
.
Additional Context
No response