-
Notifications
You must be signed in to change notification settings - Fork 60
fix: Allow hyphen and underscore in filename #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughExpanded allowed filename characters to include dash and underscore. Replaced regex-based validation with a strip-and-alnum check while retaining early returns for non-string or empty inputs. Updated unit tests to cover new valid patterns. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Validator as FileName Validator
Caller->>Validator: validate(name)
alt name is not string or empty
Validator-->>Caller: false
else
Note over Validator: Remove '.', '-', '_' from name
Validator->>Validator: ctype_alnum(remaining)
alt remaining is alphanumeric
Validator-->>Caller: true
else
Validator-->>Caller: false
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/Storage/Validator/FileNameTest.php (1)
32-34: LGTM! Test coverage aligns with the updated validation.The new test cases correctly verify that hyphens, underscores, and dots are now accepted in filenames.
Consider adding edge case tests for filenames consisting only of special characters (e.g.,
'---','___','...') to explicitly verify they are rejected, and filenames starting/ending with special characters (e.g.,'.hidden','file-') to confirm they are accepted. This would make the test suite more comprehensive.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Storage/Validator/FileName.php(2 hunks)tests/Storage/Validator/FileNameTest.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Storage/Validator/FileNameTest.php (1)
src/Storage/Validator/FileName.php (1)
isValid(23-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build & Unit
🔇 Additional comments (2)
src/Storage/Validator/FileName.php (2)
18-18: LGTM! Documentation updated accurately.The docstring now correctly describes the expanded character set, including the newly allowed hyphen and underscore.
33-33: LGTM! Validation logic is correct and more maintainable.The strip-and-check approach correctly handles the expanded character set while maintaining security:
- Filenames with only special characters (e.g.,
'---','...') are correctly rejected sincectype_alnum('')returnsfalse- Path traversal attempts (e.g.,
'../test') remain blocked because the forward slash is not removed and fails the alphanumeric check- The implementation is simpler and more readable than regex-based validation
Allows hyphen and underscore as valid characters for filename
Related: appwrite/appwrite#10501
Summary by CodeRabbit
New Features
Tests