Skip to content

Preserve file extension#40

Merged
stesee merged 6 commits into
mainfrom
PreserveFileExtension
Jul 12, 2026
Merged

Preserve file extension#40
stesee merged 6 commits into
mainfrom
PreserveFileExtension

Conversation

@stesee

@stesee stesee commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

stesee added 3 commits July 11, 2026 19:26
Introduce a new `preserveFileNameExtension` parameter (defaulting to `true`) on `Sanitize` and `SanitizeFilename` overloads so long filenames can be truncated while keeping their extension. Update truncation logic to split name/extension and enforce the 255-byte limit on the combined result. Also simplify several legacy `#if NETSTANDARD2_0` branches and add coverage for long-name truncation behavior with and without extension preservation.
Replaces the `preserveFileNameExtension` boolean parameter with a `FilenameExtensionHandling` enum, adding a third option to throw when the extension is too long to fit within the 255-byte limit. Updates all call sites and tests accordingly.
Copilot AI review requested due to automatic review settings July 11, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces configurable handling of filename extensions during the 255-byte UTF-8 truncation step, allowing callers to preserve (or not preserve) the extension, and optionally throw when an extension is too long.

Changes:

  • Added FilenameExtensionHandling enum and plumbed it through the public sanitize APIs to control extension preservation behavior.
  • Updated truncation logic to preserve extensions when requested (including handling overly long extensions).
  • Added NUnit coverage for long-filename truncation behaviors and a README “try it yourself” link.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
SanitizeFilenameTests/FilenameTests/TrunacateLongFilenames.cs Adds new tests for truncation behavior with/without extension preservation (includes a few typos to fix).
SanitizeFilename/SanitizeFilenameExtensions.cs Extends the public extension methods to pass through FilenameExtensionHandling.
SanitizeFilename/SanitizeFilename.cs Updates core sanitize entry points and truncation logic to optionally preserve extensions.
SanitizeFilename/FilenameExtensionHandling.cs Introduces the enum controlling truncation/extension behavior.
README.md Adds a dotnetfiddle link for quick experimentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SanitizeFilenameTests/FilenameTests/TrunacateLongFilenames.cs Outdated
Comment thread SanitizeFilenameTests/FilenameTests/TrunacateLongFilenames.cs Outdated
Comment thread SanitizeFilenameTests/FilenameTests/TrunacateLongFilenames.cs Outdated
Comment thread SanitizeFilename/FilenameExtensionHandling.cs Outdated
Comment thread SanitizeFilename/SanitizeFilenameExtensions.cs
Comment thread SanitizeFilename/SanitizeFilename.cs
@stesee
stesee merged commit e1d336e into main Jul 12, 2026
6 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 12, 2026
@stesee
stesee deleted the PreserveFileExtension branch July 12, 2026 08:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants