diff mod_archive_muc/mod_archive_muc.lua @ 240:ef0b580f434d

mod_archive_muc: clean up '\n ' in preference stanza
author shinysky<shinysky1986(AT)gmail.com>
date Wed, 11 Aug 2010 07:59:26 +0800
parents 5343b3ebaffb
children 6202ce4d12d6
line wrap: on
line diff
--- 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