Skip to content

fix: handle filenames without extension#10

Draft
thirdygayares wants to merge 1 commit intomainfrom
test/find-and-fix-a-bug-in-codebase
Draft

fix: handle filenames without extension#10
thirdygayares wants to merge 1 commit intomainfrom
test/find-and-fix-a-bug-in-codebase

Conversation

@thirdygayares
Copy link
Copy Markdown
Owner

Summary

  • prevent duplicate extensions when truncating filenames lacking a period
  • account for optional extension when calculating truncation lengths

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

@vercel
Copy link
Copy Markdown

vercel bot commented Aug 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pdf-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 9, 2025 3:48am

Copy link
Copy Markdown
Contributor

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 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 lastIndexOf approach
  • 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
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 3 should be extracted to a named constant to clarify it represents the length of the ellipsis ('...').

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

Copilot uses AI. Check for mistakes.
}

export default useTruncatedFilename; No newline at end of file
export default useTruncatedFilename
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
export default useTruncatedFilename
export default useTruncatedFilename;

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 7, 2026

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