Skip to content

Commit 90d6b3d

Browse files
committed
Allow more characters in file names
1 parent 4bd5d56 commit 90d6b3d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

worldedit_commands/init.lua

+13-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ local function mkdir(path)
7878
end
7979
end
8080

81+
local function check_filename(name)
82+
return name:find("^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$") ~= nil
83+
end
84+
8185

8286
minetest.register_chatcommand("/about", {
8387
params = "",
@@ -885,11 +889,10 @@ minetest.register_chatcommand("/save", {
885889
worldedit.player_notify(name, "invalid usage: " .. param)
886890
return
887891
end
888-
if not param:find("^[a-zA-Z0-9_%-.]+$") then
892+
if not check_filename(param) then
889893
worldedit.player_notify(name, "Disallowed file name: " .. param)
890894
return
891895
end
892-
893896
local result, count = worldedit.serialize(worldedit.pos1[name],
894897
worldedit.pos2[name])
895898

@@ -923,8 +926,8 @@ minetest.register_chatcommand("/allocate", {
923926
worldedit.player_notify(name, "invalid usage: " .. param)
924927
return
925928
end
926-
if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then
927-
worldedit.player_notify(name, "invalid file name: " .. param)
929+
if not check_filename(param) then
930+
worldedit.player_notify(name, "Disallowed file name: " .. param)
928931
return
929932
end
930933

@@ -1056,7 +1059,7 @@ minetest.register_chatcommand("/mtschemcreate", {
10561059
worldedit.player_notify(name, "No filename specified")
10571060
return
10581061
end
1059-
if not param:find("^[a-zA-Z0-9_%-.]+$") then
1062+
if not check_filename(param) then
10601063
worldedit.player_notify(name, "Disallowed file name: " .. param)
10611064
return
10621065
end
@@ -1083,10 +1086,14 @@ minetest.register_chatcommand("/mtschemplace", {
10831086
description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
10841087
privs = {worldedit=true},
10851088
func = function(name, param)
1086-
if param == nil then
1089+
if param == "" then
10871090
worldedit.player_notify(name, "no filename specified")
10881091
return
10891092
end
1093+
if not check_filename(param) then
1094+
worldedit.player_notify(name, "Disallowed file name: " .. param)
1095+
return
1096+
end
10901097

10911098
local pos = get_position(name)
10921099
if pos == nil then return end

0 commit comments

Comments
 (0)