Drop "[]" from parameter names in data binding

Closes gh-25836
This commit is contained in:
Rossen Stoyanchev
2020-10-07 16:44:11 +01:00
parent d05803aa04
commit fee8abfa5f
3 changed files with 46 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,6 +104,15 @@ public class WebExchangeDataBinderTests {
assertThat(this.testBean.isPostProcessed()).isFalse();
}
@Test // gh-25836
public void testFieldWithEmptyArrayIndex() {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("stringArray[]", "ONE");
formData.add("stringArray[]", "TWO");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertThat(this.testBean.getStringArray()).containsExactly("ONE", "TWO");
}
@Test
public void testFieldDefault() throws Exception {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,6 +112,18 @@ public class WebRequestDataBinderTests {
assertThat(target.isPostProcessed()).isFalse();
}
@Test // gh-25836
public void testFieldWithEmptyArrayIndex() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("stringArray[]", "ONE");
request.addParameter("stringArray[]", "TWO");
binder.bind(new ServletWebRequest(request));
assertThat(target.getStringArray()).containsExactly("ONE", "TWO");
}
@Test
public void testFieldDefault() throws Exception {
TestBean target = new TestBean();