From 924f61a48b48435a03e15d0f6d9ec8e5ad03c49f Mon Sep 17 00:00:00 2001 From: Maxime Bouillot Date: Thu, 31 Aug 2023 16:51:40 +0200 Subject: [PATCH] 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. --- z.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/z.lua b/z.lua index 224c4da..244f9c5 100755 --- a/z.lua +++ b/z.lua @@ -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()