diff --git a/src/app/ui/file_selector.cpp b/src/app/ui/file_selector.cpp index 9c5b0c08b..9992d4e1b 100644 --- a/src/app/ui/file_selector.cpp +++ b/src/app/ui/file_selector.cpp @@ -547,6 +547,18 @@ std::string FileSelector::show( } // else file-name specified in the entry is really a file to open... + if (m_type == FileSelectorType::Save) { + std::string finalFilename = base::get_file_name(buf); + if (const size_t fver = base::verify_filename(finalFilename); fver != std::string::npos) + { + Alert::show("Error<text(); + if (m_type == FileSelectorType::Save) { + if (const size_t fver = base::verify_filename(dirname); fver != std::string::npos) + { + Alert::show("Error<createDirectory(dirname); diff --git a/src/base/path.cpp b/src/base/path.cpp index 319e96bb2..478434da4 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -1,5 +1,6 @@ -// Aseprite Base Library -// Copyright (c) 2001-2016 David Capello +// Base Library +// Aseprite | Copyright (C) 2001-2016 David Capello +// LibreSprite | Copyright (C) 2026 LibreSprite contributors // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -243,4 +244,20 @@ int compare_filenames(const std::string& a, const std::string& b) return 1; } +size_t verify_filename(const std::string& filename) +{ +#ifdef _WIN32 + // In general, _wfopen() would fail for most of these characters *except slashes and colon*, + // but returning a meaningful error message to the user is always a nice practice. + const std::string invalidChars = ":?\"<>|*"; + + for (size_t it=0; it