freescout-help-desk / freescout

FreeScout — Free self-hosted help desk & shared mailbox (Zendesk / Help Scout alternative)
https://freescout.net
GNU Affero General Public License v3.0
2.94k stars 484 forks source link

Attachment URL is malformed on Windows #4106

Closed achikhv closed 2 months ago

achikhv commented 3 months ago

PHP version: 8.3 FreeScout version: 1.8.145 Database: PostgreSQL Are you using CloudFlare: No Are you using non-official modules: No

On Windows attachments URL's shown in message body are malformed. Attachment's function getStorageFilePath returns string with backslashes, that are later escaped to %5C in url function. So final attachment URL contains %5C instead of forward slashes. That results in 404 when trying to view attachment.

URL should contain only forward slashes, so it is reasonable to replace DIRECTORY_SEPARATORS returned by getStorageFilePath with forward slashes.

I propose to rewrite Attachment's url() like this:

public function url()
{
    $file_path = $this->getStorageFilePath();

    // URL must contain only forward slashes.
    $file_path = str_replace(DIRECTORY_SEPARATOR, '/', $file_path);

    $file_url = Storage::url($file_path);

    // Fix percents.
    // https://github.com/freescout-helpdesk/freescout/issues/3530
    $file_url = str_replace('%', '%25', $file_url);

    return $file_url.'?id='.$this->id.'&token='.$this->getToken();
}

I can file PR if it is OK.

freescout-help commented 3 months ago

Pull request would be appreaciated.

freescout-help commented 2 months ago

Fixed in the master branch and will be published in the next release.