]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Handle blank lines in mapstats maps
authorAlexander Moisseev <moiseev@mezonplus.ru>
Wed, 11 Feb 2026 06:41:23 +0000 (09:41 +0300)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 11 Feb 2026 09:06:19 +0000 (09:06 +0000)
Replace regex-based empty line detection with Lua pattern matching
to correctly identify and preserve blank lines instead of treating
them as syntax errors.

lualib/rspamadm/mapstats.lua

index 81fc9e8e21506fe5f395f16a6980665327548794..c6f2950b96c3cc65ed2b5360f2a7cce0c161fd46 100644 (file)
@@ -54,7 +54,6 @@ parser:option "-x --exclude-logs"
 local re_non_file_url = rspamd_regexp.create('/^.*(?<!file):\\/\\//')
 local re_regexp_line = rspamd_regexp.create('/^\\/(.+)\\/(\\S?)(?:\\s+(\\d+\\.?\\d*))?(?:\\s+#\\s*(.*))?$/')
 local re_plain_line = rspamd_regexp.create('/^(\\S+)(?:\\s+(\\d+\\.?\\d*))?(?:\\s+#\\s*(.*))?$/')
-local re_comment_line = rspamd_regexp.create('/^#|^\\s*$/')
 local re_sym_with_opts = rspamd_regexp.create('/([^(]+)\\([.0-9]+\\)\\{([^;]+);\\}/')
 
 local function get_multimap_config(config_path)
@@ -105,7 +104,8 @@ local function get_map(symbol_cfg, map_file)
   for line in fh:lines() do
     line_num = line_num + 1
 
-    if re_comment_line:match(line) then
+    local trimmed = line:match('^%s*(.-)%s*$')
+    if trimmed == '' or trimmed:match('^#') then
       table.insert(entries, {
         line_num = line_num,
         is_comment = true,