# HG changeset patch # User Kim Alvefur # Date 1341143486 -7200 # Node ID 81de1e446bfe0c709144a58e6f2bbfab4781b991 # Parent dd3b30c0dc8a086bd264e5073dfa64c59f15e9d7 mod_vjud: Don't break on undefined properties. diff -r dd3b30c0dc8a -r 81de1e446bfe mod_vjud/mod_vjud.lua --- a/mod_vjud/mod_vjud.lua Sun Jul 01 13:15:40 2012 +0200 +++ b/mod_vjud/mod_vjud.lua Sun Jul 01 13:51:26 2012 +0200 @@ -5,6 +5,7 @@ local dataforms_new = require "util.dataforms".new; local jid_split = require "util.jid".prepped_split; local vcard = module:require "vcard"; +local rawget, rawset = rawget, rawset; local st = require "util.stanza"; local template = require "util.template"; @@ -48,10 +49,12 @@ }; local vCard_mt = { __index = function(t, k) + if type(k) ~= "string" then return nil end for i=1,#t do - if t[i].name == k then - t[k] = t[i]; - return t[i] + local t_i = rawget(t, i); + if t_i and t_i.name == k then + rawset(t, k, t_i); + return t_i; end end end @@ -60,8 +63,11 @@ local function get_user_vcard(user) local vCard = dm_load(user, module.host, "vcard"); if vCard then + module:log("warn", require"util.serialization".serialize(vCard)); vCard = st.deserialize(vCard); + module:log("warn", require"util.serialization".serialize(vCard)); vCard = vcard.from_xep54(vCard); + module:log("warn", require"util.serialization".serialize(vCard)); return setmetatable(vCard, vCard_mt); end end diff -r dd3b30c0dc8a -r 81de1e446bfe mod_vjud/vcard.lib.lua --- a/mod_vjud/vcard.lib.lua Sun Jul 01 13:15:40 2012 +0200 +++ b/mod_vjud/vcard.lib.lua Sun Jul 01 13:51:26 2012 +0200 @@ -227,7 +227,6 @@ local function from_xep54_item(item) local prop_name = item.name; local prop_def = vCard_dtd[prop_name]; - if not prop_def then return nil end local prop = { name = prop_name }; @@ -299,7 +298,7 @@ local tags = vCard.tags; local t = {}; for i=1,#tags do - t[i] = from_xep54_item(tags[i]); + t_insert(t, from_xep54_item(tags[i])); end return t end @@ -312,9 +311,7 @@ local t = {}; local vCards = vCard.tags; for i=1,#vCards do - local ti = from_xep54_vCard(vCards[i]); - t[i] = ti; - --t[ti.name] = ti; + t[i] = from_xep54_vCard(vCards[i]); end return t elseif vCard.name == "vCard" then -- A single vCard