Comparison

plugins/muc/register.lib.lua @ 13871:9eee04a95a25 13.0

MUC: Fix nickname registration form error handling (fixes #1930) `dataform:data()` always returns the first table of collected values, even if there are errors, so checking for its absence did not detect when a required field (the only field, nickname) was missing.
author Kim Alvefur <zash@zash.se>
date Mon, 05 May 2025 16:32:45 +0200
parent 13300:b73547cfd736
comparison
equal deleted inserted replaced
13870:8078eebf5601 13871:9eee04a95a25
170 return true; 170 return true;
171 elseif form_type ~= "http://jabber.org/protocol/muc#register" then 171 elseif form_type ~= "http://jabber.org/protocol/muc#register" then
172 origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form")); 172 origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form"));
173 return true; 173 return true;
174 end 174 end
175 local reg_data = registration_form:data(form_tag); 175 local reg_data, form_err = registration_form:data(form_tag);
176 if not reg_data then 176 if form_err then
177 origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form")); 177 local errs = {};
178 for field, err in pairs(form_err) do
179 table.insert(errs, field..": "..err);
180 end
181 origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form: "..table.concat(errs)));
178 return true; 182 return true;
179 end 183 end
180 -- Is the nickname valid? 184 -- Is the nickname valid?
181 local desired_nick = resourceprep(reg_data["muc#register_roomnick"], true); 185 local desired_nick = resourceprep(reg_data["muc#register_roomnick"], true);
182 if not desired_nick then 186 if not desired_nick then