1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-14 11:49:48 +00:00

Change separator in data file

Using '|' as the data separator caused crashes if
a path with a '|' char in it was in the data file.
Changing that separator to a null byte ensures
that this kind of issue can never happen again as
the null byte can't be in a path.
This commit is contained in:
Maxime Bouillot
2023-08-31 16:51:40 +02:00
parent 30220996ca
commit 924f61a48b

5
z.lua
View File

@@ -128,6 +128,7 @@ Z_MATCHMODE = 0
Z_MATCHNAME = false
Z_SKIPPWD = false
Z_HYPHEN = "auto"
Z_DATA_SEPARATOR = "\0"
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
@@ -1073,7 +1074,7 @@ function data_load(filename)
return {}
end
for line in fp:lines() do
local part = string.split(line, '|')
local part = string.split(line, Z_DATA_SEPARATOR)
local item = {}
if part and part[1] and part[2] and part[3] then
local key = insensitive and part[1]:lower() or part[1]
@@ -1135,7 +1136,7 @@ function data_save(filename, M)
end
for i = 1, #M do
local item = M[i]
local text = item.name .. '|' .. item.rank .. '|' .. item.time
local text = item.name .. Z_DATA_SEPARATOR .. item.rank .. Z_DATA_SEPARATOR .. item.time
fp:write(text .. '\n')
end
fp:close()