18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-29 19:20:01 +01:00

fix(scripting): read '\' as a folder separator in scenery script paths on Linux too

The unit test reading "scripts\module.lua" failed on Linux/GCC: there '\'
is part of a file name, not a separator. The game already reads '\' in its
data paths as '/' (replace_slashes, the model and texture names, the
parser's include tokens), and sceneries made on Windows often name their
folders with it, so the scenery scripts do the same: read_script_file
turns '\' into '/' (lua_sandbox::with_forward_slashes) after the path
check. is_safe_relative_path splits on both separators on every system,
so '..\' and 'a\..\..\' stay refused; the test now checks those too.
This commit is contained in:
jerrrrycho
2026-11-13 18:35:47 +01:00
parent acda6562cd
commit 8467eab8b4
4 changed files with 19 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
#include "scripting/scriptscreenrules.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <system_error>
@@ -59,6 +60,13 @@ int api_date(lua_State *L)
} // namespace
std::string with_forward_slashes(std::string_view const Path)
{
std::string result{Path};
std::ranges::replace(result, '\\', '/');
return result;
}
void open_safe_libraries(lua_State *L)
{
open_library(L, luaopen_base, "");
@@ -121,7 +129,7 @@ std::optional<std::string> read_script_file(std::string const &Folder, std::stri
}
// a folder or a device (CON, NUL, COM1...) isn't a regular file. in the code page of the system, as the game opens
// its files
std::filesystem::path const path{Folder + std::string{Path}};
std::filesystem::path const path{Folder + with_forward_slashes(Path)};
std::error_code error;
if (false == std::filesystem::is_regular_file(path, error))
{