fs: Add allow_whitespace parameter to is_legal_user_file_name()

This is supposed to be false for the add-ons server, true (default) for
saved games.
This commit is contained in:
Iris Morelle 2021-04-07 03:49:37 -04:00
parent 7f71a6e849
commit e90067936d
3 changed files with 8 additions and 4 deletions

View File

@ -68,7 +68,7 @@ bool addon_filename_legal(const std::string& name)
// Currently just a wrapper for filesystem::is_legal_user_file_name().
// This is allowed to change in the future. Do not remove this wrapper.
// I will hunt you down if you do.
return filesystem::is_legal_user_file_name(name);
return filesystem::is_legal_user_file_name(name, false);
}
namespace {

View File

@ -252,8 +252,11 @@ inline bool is_compressed_file(const std::string& filename) {
* This is meant to be used for any files created by Wesnoth where user input
* is required, including save files and add-on files for uploading to the
* add-ons server.
*
* @param name File name to verify.
* @param allow_whitespace Whether whitespace should be allowed.
*/
bool is_legal_user_file_name(const std::string& name);
bool is_legal_user_file_name(const std::string& name, bool allow_whitespace = true);
struct file_tree_checksum
{

View File

@ -31,7 +31,7 @@ static lg::log_domain log_filesystem("filesystem");
namespace filesystem
{
bool is_legal_user_file_name(const std::string& name)
bool is_legal_user_file_name(const std::string& name, bool allow_whitespace)
{
//
// IMPORTANT NOTE:
@ -77,10 +77,11 @@ bool is_legal_user_file_name(const std::string& name)
return false; // name is an invalid UTF-8 sequence
}
return name_ucs4.end() == std::find_if(name_ucs4.begin(), name_ucs4.end(), [](char32_t c)
return name_ucs4.end() == std::find_if(name_ucs4.begin(), name_ucs4.end(), [=](char32_t c)
{
switch(c) {
case ' ':
return !allow_whitespace;
case '"':
case '*':
case '/':