dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

Wrong uri when DirectoryNamer returns '0' #1360

Closed huynguyen93 closed 1 year ago

huynguyen93 commented 1 year ago

Bug Report

Q A
BC Break no
Bundle version 1.21.1
Symfony version 6.0
PHP version 8.1

Summary

I have a custom DirectoryNamerInterface

class UserFileDirectoryNamer implements DirectoryNamerInterface
{
    public function directoryName($object, PropertyMapping $mapping): string
    {
        return '0';
    }
}

The files are uploaded to correct folder (/uploads/0/file.txt), but when I get the uri, it's wrong (/uploads/file.txt)

How to reproduce

Make a DirectoryNamer as above

Expected behavior

the uri should be correct (/uploads/0/file.txt)

I took a look at AbstractStorage, the bug is probably caused by this check $path = !empty($dir) ? $dir.'/'.$filename : $filename;

!empty('0') returns false;

garak commented 1 year ago

Duplicate of #1111