From 1eb90f539358cda123f1d2d456c3a119cec064c6 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 7a1885e8..56dfa1e8 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); } }