-
Notifications
You must be signed in to change notification settings - Fork 10
Add reserved name handling and add user filename validation #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Flamefire
merged 10 commits into
Return-To-The-Roots:master
from
MichalLabuda:add-filename-validation
Jun 30, 2026
+170
−10
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dd36255
Add reserved name handling to makePortableName and add user filename …
MichalLabuda 6383cef
Use isValidFileNameChar in isValidFileName and trim tests to one per …
MichalLabuda c1773ad
Apply suggestions from code review
MichalLabuda 2fc22bd
Add missing test case
MichalLabuda d37c01e
Merge remote changes into add-filename-validation
MichalLabuda 015b15e
Test cases restored according to suggestions from code review
MichalLabuda 70d869c
Add length check (255 code points) to isValidFileName
MichalLabuda 40b58ea
Fix isValidFileName to iterate UTF-32 code points instead of raw UTF-…
MichalLabuda f19a93c
Replace forbidden-char || chain in isValidFileNameChar with constexpr…
MichalLabuda c602e6f
Reject invalid UTF-8 and tighten length check to 255 bytes to cover L…
MichalLabuda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| // Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org) | ||
| // Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org) | ||
| // | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| /// Remove all invalid chars of a file or directory name. Result may be empty! | ||
| /// --> bfs::portable_name will return true | ||
| /// Sanitizes to a portable name. Appends '_' to Windows reserved device names. Result may be empty. | ||
| /// --> bfs::portable_name will return true for non-empty results | ||
| std::string makePortableName(const std::string& fileName); | ||
| /// Remove all invalid chars so the name can be used for a file. Result may be empty! | ||
| /// --> bfs::portable_file_name will return true | ||
| /// Sanitizes to a portable filename. Result may be empty. | ||
| /// --> bfs::portable_file_name will return true for non-empty results | ||
| std::string makePortableFileName(const std::string& fileName); | ||
| /// Remove all invalid chars so the name can be used for a directory. Result may be empty! | ||
| /// --> bfs::portable_directory_name will return true | ||
| /// Sanitizes to a portable directory name. Result may be empty. | ||
| /// --> bfs::portable_directory_name will return true for non-empty results | ||
| std::string makePortableDirName(const std::string& fileName); | ||
|
|
||
| /// Returns true if c is valid in a user-provided filename. | ||
| /// Rejects control characters and chars forbidden on Windows (< > : " / \ | ? *). | ||
| bool isValidFileNameChar(char32_t c); | ||
| /// Returns true if fileName is a valid user-provided filename. | ||
| /// Rejects reserved device names, empty names, leading/trailing dots, and trailing spaces. | ||
| bool isValidFileName(const std::string& fileName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.