Skip to content

Commit a86429a

Browse files
eydunnwilkinsona
authored andcommitted
Fix asymmetry of equals when element has trailing dashes
See gh-34804
1 parent 7b565bd commit a86429a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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
@@ -406,7 +406,7 @@ private boolean dashIgnoringElementEquals(Elements e1, Elements e2, int i) {
406406
int i2 = 0;
407407
while (i1 < l1) {
408408
if (i2 >= l2) {
409-
return false;
409+
return remainderIsNotAlphanumeric(e1, i, i1);
410410
}
411411
char ch1 = e1.charAt(i, i1);
412412
char ch2 = e2.charAt(i, i2);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@ void equalsWhenAdaptedNameMatchesDueToRemovalOfTrailingCharacters() {
702702
assertThat(name2).isEqualTo(name1);
703703
}
704704

705+
@Test
706+
void equalsSymmetricWhenNameMatchesDueToRemovalOfTrailingDashes() {
707+
ConfigurationPropertyName n1 = ConfigurationPropertyName.of("foobar");
708+
ConfigurationPropertyName n2 = ConfigurationPropertyName.of("foobar--");
709+
assertThat(n1).isEqualTo(n2);
710+
assertThat(n2).isEqualTo(n1);
711+
}
712+
705713
@Test
706714
void isValidWhenValidShouldReturnTrue() {
707715
assertThat(ConfigurationPropertyName.isValid("")).isTrue();

0 commit comments

Comments
 (0)