# HG changeset patch # User shinysky # Date 1281484766 -28800 # Node ID ef0b580f434dfe6219e8511b438ede9403ddf8d4 # Parent 2659ee3e8d56ae455f6aeddd2fada2f7c5aaa1cd mod_archive_muc: clean up '\n ' in preference stanza diff -r 2659ee3e8d56 -r ef0b580f434d mod_archive_muc/mod_archive_muc.lua --- a/mod_archive_muc/mod_archive_muc.lua Tue Aug 10 09:26:52 2010 +0800 +++ b/mod_archive_muc/mod_archive_muc.lua Wed Aug 11 07:59:26 2010 +0800 @@ -23,11 +23,26 @@ ------------------------------------------------------------ -- Utils ------------------------------------------------------------ +local function trim(s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end + +local function clean_up(t) + for i = #t, 1, -1 do + if type(t[i]) == 'table' then + clean_up(t[i]); + elseif type(t[i]) == 'string' and trim(t[i]) == '' then + table.remove(t, i); + end + end +end + local function load_prefs(node, host) return st.deserialize(dm.load(node, host, PREFS_DIR)); end local function store_prefs(data, node, host) + clean_up(data); dm.store(node, host, PREFS_DIR, st.preserialize(data)); end