-
-
Notifications
You must be signed in to change notification settings - Fork 292
Switch to use filenamify instead of abandoned sanitize-filename package #606
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR refactors filename handling by replacing the sanitize-filename package with filenamify and renaming shortenFilename to sanitizeFilename. The changes consolidate filename sanitization and length limiting into a single function call, simplifying the codebase.
Key Changes
- Replaced
sanitize-filenamedependency withfilenamify(v7.0.0) - Renamed and refactored
shortenFilenametosanitizeFilename, now handling both sanitization and length limiting in one function - Updated
MAX_FILENAME_LENGTHfrom 255 to 230 characters - Updated test expectations from
lessThan(255)tolessThanOrEqual(255)to reflect that filenames can be exactly at the maximum length
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Replaced sanitize-filename dependency with filenamify (v7.0.0) |
| lib/utils/index.js | Refactored shortenFilename to sanitizeFilename using filenamify, reduced MAX_FILENAME_LENGTH to 230, updated exports |
| lib/filename-generator/by-type.js | Removed sanitize-filename import, simplified to use single sanitizeFilename call, improved variable naming (filename → filepath) |
| lib/filename-generator/by-site-structure.js | Removed sanitize-filename import and shortenFilename call, simplified sanitizeFilepath implementation |
| test/unit/utils/utils-test.js | Updated test suite to reflect function rename and behavior changes, removed test for specific basename length |
| test/unit/filename-generator/by-type-test.js | Updated assertions to lessThanOrEqual(255), improved variable naming, updated expected sanitization behavior for special characters |
| test/unit/filename-generator/by-site-structure-test.js | Updated assertions to lessThanOrEqual(255), improved variable naming for filepath testing, updated expected sanitization behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import logger from '../logger.js'; | ||
|
|
||
| const MAX_FILENAME_LENGTH = 255; | ||
| const MAX_FILENAME_LENGTH = 230; |
Copilot
AI
Nov 8, 2025
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.
The MAX_FILENAME_LENGTH is set to 230, but the tests expect filenames to be at most 255 characters (lessThanOrEqual(255)). This creates an inconsistency where the implementation will limit filenames to 230 characters while tests verify against 255. Consider either:
- Updating
MAX_FILENAME_LENGTHto 255 to match the test expectations, or - Updating all test assertions to use
lessThanOrEqual(230)instead oflessThanOrEqual(255)
Note: The value 230 might be intentionally lower than 255 to leave room for path separators or other modifications, but this should be documented and the tests should reflect the actual limit.
| const MAX_FILENAME_LENGTH = 230; | |
| const MAX_FILENAME_LENGTH = 255; |
| } | ||
| return filename; | ||
| function sanitizeFilename (filename) { | ||
| return filenamifySanitizeFilename(filename, {replacement: '_', maxLength: MAX_FILENAME_LENGTH}); |
Copilot
AI
Nov 8, 2025
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.
The new sanitizeFilename function is missing debug logging that was present in the old shortenFilename function. The old implementation logged when a filename was shortened: logger.debug(\[utils] shorten filename: ${filename} -> ${shortFilename}`)`. Consider adding similar logging to maintain observability when filenames are sanitized or truncated, which would help with debugging issues related to filename generation.
Example:
function sanitizeFilename (filename) {
const sanitized = filenamifySanitizeFilename(filename, {replacement: '_', maxLength: MAX_FILENAME_LENGTH});
if (sanitized !== filename) {
logger.debug(`[utils] sanitize filename: ${filename} -> ${sanitized}`);
}
return sanitized;
}| return filenamifySanitizeFilename(filename, {replacement: '_', maxLength: MAX_FILENAME_LENGTH}); | |
| const sanitized = filenamifySanitizeFilename(filename, {replacement: '_', maxLength: MAX_FILENAME_LENGTH}); | |
| if (sanitized !== filename) { | |
| logger.debug(`[utils] sanitize filename: ${filename} -> ${sanitized}`); | |
| } | |
| return sanitized; |
sanitize-filename package is abandoned and there are no updates for 6+ years. Author is not active on GitHub anymore.
It was decided to switch to filenamify which provides the same functionality + functionality of shortening filenames which this module had to implement.