Skip to content

Commit 9c128f1

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-30392
2 parents 27ddcbd + 73d9e0e commit 9c128f1

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ private boolean defaultElementEquals(Elements e1, Elements e2, int i) {
448448
int i2 = 0;
449449
while (i1 < l1) {
450450
if (i2 >= l2) {
451-
return false;
451+
return remainderIsNotAlphaNumberic(e1, i, i1);
452452
}
453453
char ch1 = indexed1 ? e1.charAt(i, i1) : Character.toLowerCase(e1.charAt(i, i1));
454454
char ch2 = indexed2 ? e2.charAt(i, i2) : Character.toLowerCase(e2.charAt(i, i2));
@@ -467,17 +467,23 @@ else if (ch1 != ch2) {
467467
}
468468
}
469469
if (i2 < l2) {
470-
if (indexed2) {
470+
return remainderIsNotAlphaNumberic(e2, i, i2);
471+
}
472+
return true;
473+
}
474+
475+
private boolean remainderIsNotAlphaNumberic(Elements elements, int element, int index) {
476+
if (elements.getType(element).isIndexed()) {
477+
return false;
478+
}
479+
int length = elements.getLength(element);
480+
do {
481+
char c = Character.toLowerCase(elements.charAt(element, index++));
482+
if (ElementsParser.isAlphaNumeric(c)) {
471483
return false;
472484
}
473-
do {
474-
char ch2 = Character.toLowerCase(e2.charAt(i, i2++));
475-
if (ElementsParser.isAlphaNumeric(ch2)) {
476-
return false;
477-
}
478-
}
479-
while (i2 < l2);
480485
}
486+
while (index < length);
481487
return true;
482488
}
483489

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

+9
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,15 @@ void equalsWhenNameStartsTheSameUsingDashedCompare() {
685685
assertThat(n2).isNotEqualTo(n1);
686686
}
687687

688+
@Test
689+
void equalsWhenAdaptedNameMatchesDueToRemovalOfTrailingCharacters() {
690+
// gh-30317
691+
ConfigurationPropertyName name1 = ConfigurationPropertyName.of("example.demo");
692+
ConfigurationPropertyName name2 = ConfigurationPropertyName.adapt("example.demo$$", '.');
693+
assertThat(name1).isEqualTo(name2);
694+
assertThat(name2).isEqualTo(name1);
695+
}
696+
688697
@Test
689698
void isValidWhenValidShouldReturnTrue() {
690699
assertThat(ConfigurationPropertyName.isValid("")).isTrue();

0 commit comments

Comments
 (0)