diff --git a/src/Http/FileUpload.php b/src/Http/FileUpload.php index 23b29b87..b560399a 100644 --- a/src/Http/FileUpload.php +++ b/src/Http/FileUpload.php @@ -75,7 +75,7 @@ public function getName(): string */ public function getSanitizedName(): string { - return trim(Nette\Utils\Strings::webalize($this->name, '.', false), '.-'); + return trim(str_replace('-.', '.', Nette\Utils\Strings::webalize($this->name, '.', false)), '.-'); } diff --git a/tests/Http/FileUpload.basic.phpt b/tests/Http/FileUpload.basic.phpt index 616bbbd8..2fdd1e0d 100644 --- a/tests/Http/FileUpload.basic.phpt +++ b/tests/Http/FileUpload.basic.phpt @@ -51,6 +51,19 @@ test(function () { }); +test(function () { + $upload = new FileUpload([ + 'name' => 'logo 2020+.pdf', + 'type' => 'text/plain', + 'tmp_name' => __DIR__ . '/files/logo.png', + 'error' => 0, + 'size' => 209, + ]); + + Assert::same('logo-2020.pdf', $upload->getSanitizedName()); +}); + + test(function () { $upload = new FileUpload([ 'name' => '',