fix file name unicode issue (#28)
This commit is contained in:
parent
0ef6e0cbdd
commit
0c0a9f1349
|
@ -29,7 +29,8 @@ class StorageFileNameParser
|
|||
public function getMovedFileName(): ?string
|
||||
{
|
||||
if ($this->fileName && $this->extension) {
|
||||
return substr($this->fileName,0,50).'_'.$this->uuid.'.'.$this->extension;
|
||||
$fileName = substr($this->fileName, 0, 50).'_'.$this->uuid.'.'.$this->extension;
|
||||
return mb_convert_encoding($fileName, 'UTF-8', 'UTF-8');
|
||||
}
|
||||
return $this->uuid;
|
||||
}
|
||||
|
|
|
@ -25,3 +25,12 @@ it('can parse filenames', function () {
|
|||
expect($parsedFilename->getMovedFileName())->toBeNull();
|
||||
|
||||
});
|
||||
|
||||
it('can handles non-utf characters', function () {
|
||||
$fileName = 'Образец_для_заполнения_85e16d7b-58ed-43bc-8dce-7d3ff7d69f41.png';
|
||||
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($fileName);
|
||||
expect($parsedFilename->fileName)->toBe('Образец_для_заполнения');
|
||||
expect($parsedFilename->uuid)->toBe('85e16d7b-58ed-43bc-8dce-7d3ff7d69f41');
|
||||
expect($parsedFilename->extension)->toBe('png');
|
||||
expect($parsedFilename->getMovedFileName())->toBe($fileName);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue