strip whitespaces in generated file names

This commit is contained in:
Yuri Kuznetsov
2025-08-29 20:29:26 +03:00
parent 85843a4dd0
commit c5c7e0eda7
2 changed files with 19 additions and 1 deletions

View File

@@ -704,7 +704,7 @@ class Util
public static function sanitizeFileName(string $fileName): string
{
/** @var string */
return preg_replace("/([^\w\s\d\-_~,;:\[\]\(\).])/u", '_', $fileName);
return preg_replace("/([^\w\d\-_~,;:\[\]\(\).])/u", '_', $fileName);
}
/**

View File

@@ -1660,4 +1660,22 @@ class UtilTest extends TestCase
{
$this->assertEquals($expectedResult, Util::urlRemoveParam($url, $paramName, $suffix));
}
/**
* @return string[]
*/
static public function sanitizeFileNameList(): array
{
return [
['test%', 'test_'],
["test\n", 'test_'],
["test test", 'test_test'],
];
}
#[DataProvider('sanitizeFileNameList')]
public function testSanitizeFileName(string $input, string $expected): void
{
$this->assertEquals($expected, Util::sanitizeFileName($input));
}
}