From 0929e0c9f8a76162e76133cb937fc2884eb2e501 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Tue, 7 Oct 2025 14:51:00 +0530 Subject: [PATCH] fix: Allow hyphen and underscore in filename --- src/Storage/Validator/FileName.php | 4 ++-- tests/Storage/Validator/FileNameTest.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Storage/Validator/FileName.php b/src/Storage/Validator/FileName.php index b263e6f4..bf43b75c 100644 --- a/src/Storage/Validator/FileName.php +++ b/src/Storage/Validator/FileName.php @@ -15,7 +15,7 @@ public function getDescription(): string } /** - * The file name can only contain "a-z", "A-Z", "0-9" and "-" and not empty. + * The file name can only contain "a-z", "A-Z", "0-9", ".", "-", and "_", and not empty. * * @param mixed $name * @return bool @@ -30,7 +30,7 @@ public function isValid($name): bool return false; } - if (! \preg_match('/^[a-zA-Z0-9.]+$/', $name)) { + if (! \ctype_alnum(\str_replace(['.', '-', '_'], '', $name))) { return false; } diff --git a/tests/Storage/Validator/FileNameTest.php b/tests/Storage/Validator/FileNameTest.php index f3358bfe..0dcde9fc 100644 --- a/tests/Storage/Validator/FileNameTest.php +++ b/tests/Storage/Validator/FileNameTest.php @@ -29,5 +29,8 @@ public function testValues() $this->assertEquals($this->object->isValid('../test'), false); $this->assertEquals($this->object->isValid('test.png'), true); $this->assertEquals($this->object->isValid('test'), true); + $this->assertEquals($this->object->isValid('test-test'), true); + $this->assertEquals($this->object->isValid('test_test'), true); + $this->assertEquals($this->object->isValid('test.test-test_test'), true); } }