Diff

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
line wrap: on
line diff
--- a/plugins/muc/register.lib.lua	Mon May 05 15:05:53 2025 +0200
+++ b/plugins/muc/register.lib.lua	Mon May 05 16:32:45 2025 +0200
@@ -172,9 +172,13 @@
 			origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form"));
 			return true;
 		end
-		local reg_data = registration_form:data(form_tag);
-		if not reg_data then
-			origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form"));
+		local reg_data, form_err = registration_form:data(form_tag);
+		if form_err then
+			local errs = {};
+			for field, err in pairs(form_err) do
+				table.insert(errs, field..": "..err);
+			end
+			origin.send(st.error_reply(stanza, "modify", "bad-request", "Error in form: "..table.concat(errs)));
 			return true;
 		end
 		-- Is the nickname valid?