From bab111b37eabceeb2a52ef45d0c1a431570110a7 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 15 Nov 2018 13:48:20 -0800 Subject: [PATCH] Fix ConfigurationPropertyName.equals for uppercase Commit 7f35f8a9 for gh-14665 was unfortunately incomplete as it didn't account for uppercase values. The run-off while loop should have used `Character.toLowerCase` in the same way as the main while loop. Fixes gh-15152 --- .../source/ConfigurationPropertyName.java | 2 +- .../ConfigurationPropertyNameTests.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index f4b31f8259..6c798ad833 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -347,7 +347,7 @@ public final class ConfigurationPropertyName } } while (i2 < l2) { - char ch2 = e2.charAt(i, i2++); + char ch2 = Character.toLowerCase(e2.charAt(i, i2++)); if (indexed2 || ElementsParser.isAlphaNumeric(ch2)) { return false; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java index 43bfa6de13..4739f8f5c3 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java @@ -609,6 +609,26 @@ public class ConfigurationPropertyNameTests { assertThat(n1).isNotEqualTo(n2); } + @Test + public void equalsWhenStartsWithOfAdaptedName() { + // gh-15152 + ConfigurationPropertyName n1 = ConfigurationPropertyName + .adapt("example.mymap.ALPHA", '.'); + ConfigurationPropertyName n2 = ConfigurationPropertyName + .adapt("example.mymap.ALPHA_BRAVO", '.'); + assertThat(n1).isNotEqualTo(n2); + } + + @Test + public void equalsWhenStartsWithOfAdaptedNameOfIllegalChars() { + // gh-15152 + ConfigurationPropertyName n1 = ConfigurationPropertyName + .adapt("example.mymap.ALPH!", '.'); + ConfigurationPropertyName n2 = ConfigurationPropertyName + .adapt("example.mymap.ALPHA!BRAVO", '.'); + assertThat(n1).isNotEqualTo(n2); + } + @Test public void isValidWhenValidShouldReturnTrue() { assertThat(ConfigurationPropertyName.isValid("")).isTrue();