mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Merge pull request #493 from abyss638/accept_empty_form_label
Accept empty string as form field label value
This commit is contained in:
commit
bd528d2c32
3 changed files with 47 additions and 1 deletions
|
@ -33,6 +33,7 @@ import org.jivesoftware.smack.util.CollectionUtil;
|
||||||
import org.jivesoftware.smack.util.EqualsUtil;
|
import org.jivesoftware.smack.util.EqualsUtil;
|
||||||
import org.jivesoftware.smack.util.HashCode;
|
import org.jivesoftware.smack.util.HashCode;
|
||||||
import org.jivesoftware.smack.util.MultiMap;
|
import org.jivesoftware.smack.util.MultiMap;
|
||||||
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
|
@ -600,7 +601,7 @@ public abstract class FormField implements XmlElement {
|
||||||
* @return a reference to this builder.
|
* @return a reference to this builder.
|
||||||
*/
|
*/
|
||||||
public B setLabel(String label) {
|
public B setLabel(String label) {
|
||||||
this.label = StringUtils.requireNotNullNorEmpty(label, "label must not be null or empty");
|
this.label = Objects.requireNonNull(label, "label must not be null");
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package org.jivesoftware.smackx.xdata;
|
package org.jivesoftware.smackx.xdata;
|
||||||
|
|
||||||
import static org.jivesoftware.smack.test.util.XmlAssertUtil.assertXmlSimilar;
|
import static org.jivesoftware.smack.test.util.XmlAssertUtil.assertXmlSimilar;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.jxmpp.jid.JidTestUtil;
|
import org.jxmpp.jid.JidTestUtil;
|
||||||
|
@ -35,4 +37,18 @@ class FormFieldTest {
|
||||||
assertXmlSimilar(expectedXml, xml);
|
assertXmlSimilar(expectedXml, xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyLabel() {
|
||||||
|
TextSingleFormField.Builder builder = FormField.textSingleBuilder("type");
|
||||||
|
builder.setLabel("");
|
||||||
|
TextSingleFormField formField = builder.build();
|
||||||
|
|
||||||
|
assertEquals("", formField.getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testThrowExceptionWhenNullLabel() {
|
||||||
|
TextSingleFormField.Builder builder = FormField.textSingleBuilder("type");
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> builder.setLabel(null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,4 +115,33 @@ public class DataFormProviderTest {
|
||||||
assertEquals(2, items.size());
|
assertEquals(2, items.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRetrieveFieldWithEmptyLabel() throws XmlPullParserException, IOException, SmackParsingException {
|
||||||
|
|
||||||
|
String form =
|
||||||
|
"<x xmlns='jabber:x:data' type='form'>" +
|
||||||
|
" <title>Advanced User Search</title>" +
|
||||||
|
" <instructions>The following fields are available for searching. Wildcard (*) characters are allowed as part of the query.</instructions>" +
|
||||||
|
" <field var='FORM_TYPE' label='' type='hidden'>" +
|
||||||
|
" <value>jabber:iq:search</value>" +
|
||||||
|
" </field>" +
|
||||||
|
" <field label='Search' var='search'>" +
|
||||||
|
" <required/>" +
|
||||||
|
" </field>" +
|
||||||
|
" <field label='Username' var='Username' type='boolean'>" +
|
||||||
|
" <value>true</value>" +
|
||||||
|
" </field>" +
|
||||||
|
" <field label='Name' var='Name' type='boolean'>" +
|
||||||
|
" <value>true</value>" +
|
||||||
|
" </field>" +
|
||||||
|
" <field label='Email' var='Email' type='boolean'>" +
|
||||||
|
" <value>true</value>" +
|
||||||
|
" </field>" +
|
||||||
|
"</x>";
|
||||||
|
XmlPullParser parser = PacketParserUtils.getParserFor(form);
|
||||||
|
DataForm dataForm = DataFormProvider.INSTANCE.parse(parser);
|
||||||
|
FormField usernameFormField = dataForm.getField("FORM_TYPE");
|
||||||
|
assertEquals(FormField.Type.hidden, usernameFormField.getType());
|
||||||
|
assertEquals("", usernameFormField.getLabel());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue