defend against malformed formspecs
This commit is contained in:
parent
7cb0c49f09
commit
6c14da350b
19
init.lua
19
init.lua
@ -238,6 +238,9 @@ end
|
||||
|
||||
|
||||
local function coords_from_string(str)
|
||||
if type(str) ~= "string" then
|
||||
return nil
|
||||
end
|
||||
-- parse "1,2,3" or "1 2 3" or "(1,2,3)" or "{x=1,y=2,z=3}" or return nil on fail
|
||||
local function parse(str)
|
||||
str = trim(str)
|
||||
@ -378,18 +381,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- set new compass meta
|
||||
local meta = compass_item:get_meta()
|
||||
|
||||
local color = tonumber("0x"..fields.color, 16)
|
||||
if color then
|
||||
color = math.max(math.min(color, 0xFFFFFF), 0x0) -- for some reason seems to work fine without this
|
||||
set_compass_meta_color(meta, color)
|
||||
-- print(dump(meta:to_table()))
|
||||
if type(fields.color) == "string" then
|
||||
local color = tonumber("0x" .. fields.color, 16)
|
||||
if color then
|
||||
color = math.max(math.min(color, 0xFFFFFF), 0x0) -- for some reason seems to work fine without this
|
||||
set_compass_meta_color(meta, color)
|
||||
-- print(dump(meta:to_table()))
|
||||
end
|
||||
end
|
||||
|
||||
local coords = coords_from_string(fields.coords)
|
||||
local label = fields.label
|
||||
local label = fields.label or ""
|
||||
|
||||
-- player pressed "copy" button, ignore the "coordinates field"
|
||||
if fields.set_recent then
|
||||
if fields.set_recent and type(fields.recent) == "string" then
|
||||
local coord_string = fields.recent:match("%S+") or ""
|
||||
coords = coords_from_string(coord_string)
|
||||
label = fields.recent:match("(%S+ |[^>]+)>") or ""
|
||||
|
Loading…
Reference in New Issue
Block a user