Merge branch '2.0.x'

pull/14168/head
Madhura Bhave 6 years ago
commit b03f8e4a4a

@ -330,10 +330,10 @@ public final class ConfigurationPropertyName
} }
char ch1 = indexed1 ? e1.charAt(i1) : Character.toLowerCase(e1.charAt(i1)); char ch1 = indexed1 ? e1.charAt(i1) : Character.toLowerCase(e1.charAt(i1));
char ch2 = indexed2 ? e2.charAt(i2) : Character.toLowerCase(e2.charAt(i2)); char ch2 = indexed2 ? e2.charAt(i2) : Character.toLowerCase(e2.charAt(i2));
if (ch1 == '-' || ch1 == '_') { if (!indexed1 && (ch1 == '-' || ch1 == '_')) {
i1++; i1++;
} }
else if (ch2 == '-' || ch2 == '_') { else if (!indexed2 && (ch2 == '-' || ch2 == '_')) {
i2++; i2++;
} }
else if (ch1 != ch2) { else if (ch1 != ch2) {
@ -346,7 +346,7 @@ public final class ConfigurationPropertyName
} }
while (i2 < l2 - offset2) { while (i2 < l2 - offset2) {
char ch = e2.charAt(i2++); char ch = e2.charAt(i2++);
if (ch != '-' && ch != '_') { if (indexed2 || (ch != '-' && ch != '_')) {
return false; return false;
} }
} }

@ -783,6 +783,26 @@ public class ConfigurationPropertiesTests {
load(PersonProperties.class, "test=boot"); load(PersonProperties.class, "test=boot");
} }
@Test
public void loadWhenConfigurationPropertiesContainsMapWithPositiveAndNegativeIntegerKeys() {
// gh-14136
MutablePropertySources sources = this.context.getEnvironment()
.getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.map.x.[-1].a", "baz");
source.put("test.map.x.1.a", "bar");
source.put("test.map.x.1.b", 1);
sources.addLast(new MapPropertySource("test", source));
load(WithIntegerMapProperties.class);
WithIntegerMapProperties bean = this.context
.getBean(WithIntegerMapProperties.class);
Map<Integer, Foo> x = bean.getMap().get("x");
assertThat(x.get(-1).getA()).isEqualTo("baz");
assertThat(x.get(-1).getB()).isEqualTo(0);
assertThat(x.get(1).getA()).isEqualTo("bar");
assertThat(x.get(1).getB()).isEqualTo(1);
}
private AnnotationConfigApplicationContext load(Class<?> configuration, private AnnotationConfigApplicationContext load(Class<?> configuration,
String... inlinedProperties) { String... inlinedProperties) {
return load(new Class<?>[] { configuration }, inlinedProperties); return load(new Class<?>[] { configuration }, inlinedProperties);
@ -1557,6 +1577,22 @@ public class ConfigurationPropertiesTests {
} }
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "test")
static class WithIntegerMapProperties {
private Map<String, Map<Integer, Foo>> map;
public Map<String, Map<Integer, Foo>> getMap() {
return this.map;
}
public void setMap(Map<String, Map<Integer, Foo>> map) {
this.map = map;
}
}
@EnableConfigurationProperties @EnableConfigurationProperties
@ConfigurationProperties(prefix = "com.example", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "com.example", ignoreUnknownFields = false)
static class SimplePrefixedProperties { static class SimplePrefixedProperties {
@ -1796,4 +1832,28 @@ public class ConfigurationPropertiesTests {
} }
static class Foo {
private String a;
private int b;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
public int getB() {
return this.b;
}
public void setB(int b) {
this.b = b;
}
}
} }

@ -558,6 +558,10 @@ public class ConfigurationPropertyNameTests {
ConfigurationPropertyName n09 = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName n09 = ConfigurationPropertyName.of("foo");
ConfigurationPropertyName n10 = ConfigurationPropertyName.of("fo"); ConfigurationPropertyName n10 = ConfigurationPropertyName.of("fo");
ConfigurationPropertyName n11 = ConfigurationPropertyName.adapt("foo.BaR", '.'); ConfigurationPropertyName n11 = ConfigurationPropertyName.adapt("foo.BaR", '.');
ConfigurationPropertyName n12 = ConfigurationPropertyName.of("f-o-o[b-a-r]");
ConfigurationPropertyName n13 = ConfigurationPropertyName.of("f-o-o[b-a-r--]");
ConfigurationPropertyName n14 = ConfigurationPropertyName.of("[1]");
ConfigurationPropertyName n15 = ConfigurationPropertyName.of("[-1]");
assertThat(n01.hashCode()).isEqualTo(n02.hashCode()); assertThat(n01.hashCode()).isEqualTo(n02.hashCode());
assertThat(n01.hashCode()).isEqualTo(n02.hashCode()); assertThat(n01.hashCode()).isEqualTo(n02.hashCode());
assertThat(n01.hashCode()).isEqualTo(n03.hashCode()); assertThat(n01.hashCode()).isEqualTo(n03.hashCode());
@ -574,6 +578,8 @@ public class ConfigurationPropertyNameTests {
assertThat((Object) n07).isNotEqualTo(n08); assertThat((Object) n07).isNotEqualTo(n08);
assertThat((Object) n09).isNotEqualTo(n10); assertThat((Object) n09).isNotEqualTo(n10);
assertThat((Object) n10).isNotEqualTo(n09); assertThat((Object) n10).isNotEqualTo(n09);
assertThat((Object) n12).isNotEqualTo(n13);
assertThat((Object) n14).isNotEqualTo(n15);
} }
@Test @Test

Loading…
Cancel
Save