changeset 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 2659ee3e8d56
children 665552d75ee2
files mod_archive_muc/mod_archive_muc.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
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