The fix is not how the issue needs to be addressed.

See gh-34121
This commit is contained in:
rstoyanchev 2025-02-04 19:08:52 +00:00
parent bb7ce21076
commit 3898482d3f
3 changed files with 3 additions and 30 deletions

View File

@ -19,6 +19,7 @@ package org.springframework.test.web.servlet.samples.spr;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
@ -56,6 +57,7 @@ class ServletRequestDataBinderIntegrationTests {
.andExpect(content().string("valueB")); .andExpect(content().string("valueB"));
} }
@Disabled("see gh-34121")
@Test // gh-34121 @Test // gh-34121
void postArrayWithEmptyIndex(WebApplicationContext wac) throws Exception { void postArrayWithEmptyIndex(WebApplicationContext wac) throws Exception {
MockMvc mockMvc = webAppContextSetup(wac).build(); MockMvc mockMvc = webAppContextSetup(wac).build();
@ -86,6 +88,7 @@ class ServletRequestDataBinderIntegrationTests {
.andExpect(content().string("valueB")); .andExpect(content().string("valueB"));
} }
@Disabled("see gh-34121")
@Test // gh-34121 @Test // gh-34121
void postListWithEmptyIndex(WebApplicationContext wac) throws Exception { void postListWithEmptyIndex(WebApplicationContext wac) throws Exception {
MockMvc mockMvc = webAppContextSetup(wac).build(); MockMvc mockMvc = webAppContextSetup(wac).build();

View File

@ -244,10 +244,6 @@ public class ServletRequestDataBinder extends WebDataBinder {
@Nullable @Nullable
protected Object getRequestParameter(String name, Class<?> type) { protected Object getRequestParameter(String name, Class<?> type) {
Object value = this.request.getParameterValues(name); Object value = this.request.getParameterValues(name);
if (value == null && !name.endsWith("[]") &&
(List.class.isAssignableFrom(type) || type.isArray())) {
value = this.request.getParameterValues(name + "[]");
}
return (ObjectUtils.isArray(value) && Array.getLength(value) == 1 ? Array.get(value, 0) : value); return (ObjectUtils.isArray(value) && Array.getLength(value) == 1 ? Array.get(value, 0) : value);
} }

View File

@ -93,32 +93,6 @@ class ServletRequestDataBinderTests {
assertThat(target.isPostProcessed()).isFalse(); assertThat(target.isPostProcessed()).isFalse();
} }
@Test
public void testFieldWithArrayIndex() {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
binder.setIgnoreUnknownFields(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("stringArray[0]", "ONE");
request.addParameter("stringArray[1]", "TWO");
binder.bind(request);
assertThat(target.getStringArray()).containsExactly("ONE", "TWO");
}
@Test
public void testFieldWithEmptyArrayIndex() {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
binder.setIgnoreUnknownFields(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("stringArray[]", "ONE");
request.addParameter("stringArray[]", "TWO");
binder.bind(request);
assertThat(target.getStringArray()).containsExactly("ONE", "TWO");
}
@Test @Test
void testFieldDefault() { void testFieldDefault() {
TestBean target = new TestBean(); TestBean target = new TestBean();