Skip to content

Commit 7467fef

Browse files
committed
Fix filename cleaning
1 parent f6940da commit 7467fef

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

component/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public static function cleanFilename(string $fileName): string
4444
['Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u']
4545
);
4646

47+
$fileName = str_replace('\'', ' ', $fileName);
48+
$fileName = preg_replace('/\s+/', ' ', $fileName);
49+
$fileName = trim($fileName);
4750
$fileName = preg_replace(['/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'], ['_', '.', ''], $fileName);
4851

4952
$extension = strtolower($extension);

component/Zip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Zip extends File
1111
{
1212
public function unarchive(?string $unarchiveDirectory = null): ?array
1313
{
14-
if (! $this->exist()) {
14+
if (!$this->exist()) {
1515
return null;
1616
}
1717

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=8.1"
13+
"php": ">=8.2"
1414
},
1515
"require-dev": {
16-
"friendsofphp/php-cs-fixer": "^3.0",
17-
"phpstan/phpstan": "^1.4",
18-
"phpunit/phpunit": "^9.5"
16+
"friendsofphp/php-cs-fixer": "3.*",
17+
"phpstan/phpstan": "1.*",
18+
"phpunit/phpunit": "9.*"
1919
},
2020
"scripts": {
2121
"lint": "vendor/bin/php-cs-fixer fix ./ --rules=@PSR12",

test/FileTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626

2727
public function tearDown(): void
2828
{
29-
if (! file_exists($this->filePath)) {
29+
if (!file_exists($this->filePath)) {
3030
return;
3131
}
3232

@@ -58,15 +58,15 @@ public function testGetTemoraryDirectory(): void
5858

5959
public function testCleanFilename(): void
6060
{
61-
$result = File::cleanFilename(' µ û ');
61+
$result = File::cleanFilename(' µ \' û ');
6262

6363
$this->assertIsString($result);
64-
$this->assertEquals('_u_u_', $result);
64+
$this->assertEquals('u_u', $result);
6565

6666
$result = File::cleanFilename(' µ û . Jpg');
6767

6868
$this->assertIsString($result);
69-
$this->assertEquals('_u_u_.jpg', $result);
69+
$this->assertEquals('u_u.jpg', $result);
7070
}
7171

7272
public function testDownload(): void

0 commit comments

Comments
 (0)