mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
strip whitespaces in generated file names
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user