Skip to content

Conversation

@aivus
Copy link
Member

@aivus aivus commented Nov 1, 2025

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.

@aivus aivus requested a review from s0ph1e November 2, 2025 16:00
@s0ph1e s0ph1e requested a review from Copilot November 8, 2025 12:51
Copy link

Copilot AI left a 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-filename dependency with filenamify (v7.0.0)
  • Renamed and refactored shortenFilename to sanitizeFilename, now handling both sanitization and length limiting in one function
  • Updated MAX_FILENAME_LENGTH from 255 to 230 characters
  • Updated test expectations from lessThan(255) to lessThanOrEqual(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;
Copy link

Copilot AI Nov 8, 2025

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:

  1. Updating MAX_FILENAME_LENGTH to 255 to match the test expectations, or
  2. Updating all test assertions to use lessThanOrEqual(230) instead of lessThanOrEqual(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.

Suggested change
const MAX_FILENAME_LENGTH = 230;
const MAX_FILENAME_LENGTH = 255;

Copilot uses AI. Check for mistakes.
}
return filename;
function sanitizeFilename (filename) {
return filenamifySanitizeFilename(filename, {replacement: '_', maxLength: MAX_FILENAME_LENGTH});
Copy link

Copilot AI Nov 8, 2025

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;
}
Suggested change
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;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants