Skip to content

Commit 10e67f8

Browse files
committed
Fix dashIgnoringElementEquals algorithm
Update `dashIgnoringElementEquals` so that trailing checks fail if the last characters are not all `-`. Fixes gh-16855
1 parent 963a544 commit 10e67f8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ else if (ch1 != ch2) {
397397
boolean indexed2 = e2.getType(i).isIndexed();
398398
while (i2 < l2) {
399399
char ch2 = e2.charAt(i, i2++);
400-
if (indexed2 || ch2 == '-') {
400+
if (indexed2 || ch2 != '-') {
401401
return false;
402402
}
403403
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,16 @@ public void equalsWhenStartsWithOfAdaptedNameOfIllegalChars() {
624624
assertThat(n1).isNotEqualTo(n2);
625625
}
626626

627+
@Test
628+
public void equalsWhenNameStartsTheSameUsingDashedCompare() {
629+
// gh-16855
630+
ConfigurationPropertyName n1 = ConfigurationPropertyName
631+
.of("management.metrics.web.server.auto-time-request");
632+
ConfigurationPropertyName n2 = ConfigurationPropertyName
633+
.of("management.metrics.web.server.auto-time-requests");
634+
assertThat(n1).isNotEqualTo(n2);
635+
}
636+
627637
@Test
628638
public void isValidWhenValidShouldReturnTrue() {
629639
assertThat(ConfigurationPropertyName.isValid("")).isTrue();

0 commit comments

Comments
 (0)