1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-18 20:25:59 +02:00

Merge pull request #621 from Flowdalic/fillable-forms-only-require-list-fields-to-have-value-set

[xdata] Only require list-multi and list-single fields to have a value
This commit is contained in:
Florian Schmaus 2024-09-02 18:56:02 +00:00 committed by GitHub
commit 38c6dd21b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,6 +30,8 @@ import org.jivesoftware.smackx.xdata.AbstractMultiFormField;
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;
@ -226,11 +228,20 @@ public class FillableForm extends FilledForm {
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();
}