18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-28 20:53:22 +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

@@ -148,8 +148,11 @@ TEST_CASE("lua sandbox: a scenery reads its scripts only from its own folder") {
CHECK(lua_sandbox::read_script_file(folder, "test.lua") == std::optional<std::string>{"return 2"});
CHECK(lua_sandbox::read_script_file(folder, "scripts/module.lua") == std::optional<std::string>{"return 3"});
// '\' separates the folders on Linux too, as in the rest of the scenery's paths
CHECK(lua_sandbox::with_forward_slashes("a\\b/c\\d.lua") == "a/b/c/d.lua");
CHECK(lua_sandbox::read_script_file(folder, "scripts\\module.lua") == std::optional<std::string>{"return 3"});
for (auto const &path : {std::string{"../outside.lua"}, std::string{"scripts/../../outside.lua"}, std::string{"..\\outside.lua"},
std::string{"scripts\\..\\..\\outside.lua"}, std::string{"scripts/..\\../outside.lua"},
root.path("outside.lua"), std::string{"/outside.lua"}, std::string{"\\outside.lua"}, std::string{"C:outside.lua"},
std::string{"missing.lua"}, std::string{"folder.lua"}, std::string{"scripts"}, std::string{}}) {
CAPTURE(path);