Merge branch '3.1.x'

Closes gh-36146
pull/35874/head
Andy Wilkinson 1 year ago
commit 9d5cc11e16

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -406,7 +406,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
int i2 = 0; int i2 = 0;
while (i1 < l1) { while (i1 < l1) {
if (i2 >= l2) { if (i2 >= l2) {
return false; return remainderIsDashes(e1, i, i1);
} }
char ch1 = e1.charAt(i, i1); char ch1 = e1.charAt(i, i1);
char ch2 = e2.charAt(i, i2); char ch2 = e2.charAt(i, i2);
@ -487,6 +487,21 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
return true; return true;
} }
private boolean remainderIsDashes(Elements elements, int element, int index) {
if (elements.getType(element).isIndexed()) {
return false;
}
int length = elements.getLength(element);
do {
char c = Character.toLowerCase(elements.charAt(element, index++));
if (c != '-') {
return false;
}
}
while (index < length);
return true;
}
@Override @Override
public int hashCode() { public int hashCode() {
int hashCode = this.hashCode; int hashCode = this.hashCode;

@ -692,15 +692,22 @@ class ConfigurationPropertyNameTests {
assertThat(n2).isNotEqualTo(n1); assertThat(n2).isNotEqualTo(n1);
} }
@Test @Test // gh-30317
void equalsWhenAdaptedNameMatchesDueToRemovalOfTrailingCharacters() { void equalsWhenAdaptedNameMatchesDueToRemovalOfTrailingNonUniformCharacters() {
// gh-30317
ConfigurationPropertyName name1 = ConfigurationPropertyName.of("example.demo"); ConfigurationPropertyName name1 = ConfigurationPropertyName.of("example.demo");
ConfigurationPropertyName name2 = ConfigurationPropertyName.adapt("example.demo$$", '.'); ConfigurationPropertyName name2 = ConfigurationPropertyName.adapt("example.demo$$", '.');
assertThat(name1).isEqualTo(name2); assertThat(name1).isEqualTo(name2);
assertThat(name2).isEqualTo(name1); assertThat(name2).isEqualTo(name1);
} }
@Test // gh-34804
void equalsSymmetricWhenNameMatchesDueToIgnoredTrailingDashes() {
ConfigurationPropertyName n1 = ConfigurationPropertyName.of("example.demo");
ConfigurationPropertyName n2 = ConfigurationPropertyName.of("example.demo--");
assertThat(n2).isEqualTo(n1);
assertThat(n1).isEqualTo(n2);
}
@Test @Test
void isValidWhenValidShouldReturnTrue() { void isValidWhenValidShouldReturnTrue() {
assertThat(ConfigurationPropertyName.isValid("")).isTrue(); assertThat(ConfigurationPropertyName.isValid("")).isTrue();

Loading…
Cancel
Save