In version 6.0.0-rc.7, the GitLabForm class has a method withParam(String name, List<T> values, boolean required) for handling lists of values. However, this method overrides the previously added values in the list when adding parameters to formValues. As a result, only the last value from the list is retained.
Problematic Code
for (T value : values) {
if (value != null) {
formValues.put(name + "[]", value.toString());
}
}
In the above code, formValues.put() is used. Since Map does not allow duplicate keys, each new value with the same key (name + "[]") overrides the previous one.
Expected Behavior
The method should allow multiple values for the same parameter (e.g., appending to a list instead of overwriting). This is required for correctly sending form or query parameters like name[]=value1&name[]=value2.
Actual Behavior
Only the last value from the list is added to formValues.
Steps to Reproduce
- Create an instance of
GitLabForm.
- Call
withParam("names", Arrays.asList("value1", "value2", "value3")).
- Retrieve
getFormValues() and check the result.
Sample Code:
GitLabForm form = new GitLabForm();
form.withParam("names", Arrays.asList("value1", "value2", "value3"));
System.out.println(form.getFormValues());
Actual Output:
Expected Output:
{names[]=[value1, value2, value3]}
In version 6.0.0-rc.7, the
GitLabFormclass has a methodwithParam(String name, List<T> values, boolean required)for handling lists of values. However, this method overrides the previously added values in the list when adding parameters toformValues. As a result, only the last value from the list is retained.Problematic Code
In the above code,
formValues.put()is used. SinceMapdoes not allow duplicate keys, each new value with the same key (name + "[]") overrides the previous one.Expected Behavior
The method should allow multiple values for the same parameter (e.g., appending to a list instead of overwriting). This is required for correctly sending form or query parameters like
name[]=value1&name[]=value2.Actual Behavior
Only the last value from the list is added to
formValues.Steps to Reproduce
GitLabForm.withParam("names", Arrays.asList("value1", "value2", "value3")).getFormValues()and check the result.Sample Code:
Actual Output:
Expected Output: