fix: Handle non-ASCII characters in sanitizeFilename (#1132)

## Summary

**What is the goal of this PR?**

Probable fix for #1118. `sanitizeFilename` was only passing through
ASCII characters from filenames. It now maintains valid UTF-8
codepoints, including non-ASCII multibyte sequences. Truncation happens
at a maximum number of bytes, rather than characters, to prevent
filenames with many multibyte sequences from unexpectedly exceeding
FAT32 limits.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**YES, I described #1118
to Claude and it suggested sanitizeFilename as the likely cause**_
This commit is contained in:
Zach Nelson
2026-02-24 17:43:58 -06:00
committed by GitHub
parent 65b6bd536c
commit 9deeb2183c
2 changed files with 31 additions and 21 deletions
+2 -2
View File
@@ -9,9 +9,9 @@ namespace StringUtils {
/**
* Sanitize a string for use as a filename.
* Replaces invalid characters with underscores, trims spaces/dots,
* and limits length to maxLength characters.
* and limits length to maxBytes bytes.
*/
std::string sanitizeFilename(const std::string& name, size_t maxLength = 100);
std::string sanitizeFilename(const std::string& name, size_t maxBytes = 100);
/**
* Check if the given filename ends with the specified extension (case-insensitive).