Skip to content

[Mime] TextPart does not check for file path #57258

@Neirda24

Description

@Neirda24

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

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