Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the filename truncation logic to properly handle filenames without extensions. The fix prevents duplicate extensions and correctly calculates truncation lengths for files that lack a file extension.
Key changes:
- Replace regex-based extension extraction with
lastIndexOfapproach - Add conditional logic to handle files without extensions
- Update truncation length calculation to account for optional extensions
|
|
||
| const keepStart = Math.floor((maxLength - ext!.length - 5) / 2) | ||
| const keepEnd = Math.ceil((maxLength - ext!.length - 5) / 2) | ||
| const reserved = 3 + (hasExtension ? ext.length + 1 : 0) // ellipsis + optional dot and extension |
There was a problem hiding this comment.
The magic number 3 should be extracted to a named constant to clarify it represents the length of the ellipsis ('...').
| const reserved = 3 + (hasExtension ? ext.length + 1 : 0) // ellipsis + optional dot and extension | |
| const reserved = ELLIPSIS.length + (hasExtension ? ext.length + 1 : 0) // ellipsis + optional dot and extension |
| } | ||
|
|
||
| export default useTruncatedFilename; No newline at end of file | ||
| export default useTruncatedFilename |
There was a problem hiding this comment.
[nitpick] The semicolon was removed from the export statement. For consistency with the rest of the codebase, consider keeping the semicolon as it was present in the original code.
| export default useTruncatedFilename | |
| export default useTruncatedFilename; |
|



Summary
Testing
npm test(fails: Missing script: "test")npm run lint(fails: Unexpected any, no-unescaped-entities, etc.)https://chatgpt.com/codex/tasks/task_e_6896c1100834832a9e4869275c9ae5de