feat: Refactor the code in helpers.lua to use escaped settings and server names for matching multiple settings. This ensures that the correct values are assigned to the corresponding variables.

This commit is contained in:
Théophile Diot 2024-07-23 14:13:12 +01:00
parent 519d1cc818
commit f09db9e9dd
No known key found for this signature in database
GPG key ID: FA995104A0BA376A

View file

@ -263,18 +263,21 @@ function helpers.load_variables(all_variables, plugins)
end
end
for setting, data in pairs(all_settings) do
local escaped_setting = setting:gsub("([^%w])", "%%%1")
if all_variables[setting] then
variables["global"][setting] = all_variables[setting]
end
if data.multiple then
for variable, value in pairs(all_variables) do
local multiple_setting = variable:match("^(" .. setting .. "_%d+)$")
local multiple_setting = variable:match("^(" .. escaped_setting .. "_%d+)$")
if multiple_setting then
variables["global"][multiple_setting] = value
end
if multisite then
for _, server_name in ipairs(server_names) do
multiple_setting = variable:match("^" .. server_name .. "_(" .. setting .. "_%d+)$")
local escaped_server_name = server_name:gsub("([^%w])", "%%%1")
multiple_setting =
variable:match("^" .. escaped_server_name .. "_(" .. escaped_setting .. "_%d+)$")
if multiple_setting then
variables[server_name][multiple_setting] = value
end