Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xdata] Only require list-multi and list-single fields to have a value #621

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.jivesoftware.smackx.xdata.AbstractSingleStringValueFormField;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.FormFieldChildElement;
import org.jivesoftware.smackx.xdata.ListMultiFormField;
import org.jivesoftware.smackx.xdata.ListSingleFormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;

import org.jxmpp.jid.Jid;
Expand Down Expand Up @@ -226,11 +228,20 @@ public final void write(FormField filledFormField) {
if (filledFormField.getType() == FormField.Type.fixed) {
throw new IllegalArgumentException();
}
if (!filledFormField.hasValueSet()) {
throw new IllegalArgumentException();
}

String fieldName = filledFormField.getFieldName();

boolean isListField = filledFormField instanceof ListMultiFormField
|| filledFormField instanceof ListSingleFormField;
// Only list-* fields require a value to be set. Other fields types can be empty. For example MUC's
// muc#roomconfig_roomadmins, which is of type jid-multi, is submitted without values to reset the room's admin
// list.
if (isListField && !filledFormField.hasValueSet()) {
throw new IllegalArgumentException("Tried to write form field " + fieldName + " of type "
+ filledFormField.getType()
+ " without any values set. However, according to XEP-0045 § 3.3 fields of type list-multi or list-single must have one item set.");
}

if (!getDataForm().hasField(fieldName)) {
throw new IllegalArgumentException();
}
Expand Down
Loading