Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ private static Elements probablySingleElementOf(CharSequence name) {
}
throw new InvalidConfigurationPropertyNameException(name, Collections.singletonList('.'));
}
for (int i = 0; i < name.length() - 1; i++) {
if (name.charAt(i) == '.' && name.charAt(i + 1) == '.') {
// A repeated separator produces an empty element between the two dots.
// ElementsParser.add silently drops empty elements, which would
// otherwise make this name indistinguishable from the same name with
// the repeated separator collapsed to one (e.g. "foo..bar" parsing as
// identical to "foo.bar"), silently merging two distinct names.
if (returnNullIfInvalid) {
return null;
}
throw new InvalidConfigurationPropertyNameException(name, Collections.singletonList('.'));
}
}
if (name.charAt(name.length() - 1) == '[') {
if (returnNullIfInvalid) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ void ofNameShouldNotEndWithDot() {
.withMessageContaining("is not valid");
}

@Test
void ofNameShouldNotContainDoubleDot() {
// A repeated separator produces an empty element, which ElementsParser.add
// silently drops. Without this check, "foo..bar" parses as identical to
// "foo.bar" (of("foo..bar").equals(of("foo.bar")) is true and
// isValid("foo..bar") is true), so two distinct property-source keys that
// differ only by a repeated separator silently collide on the same
// ConfigurationPropertyName.
assertThatExceptionOfType(InvalidConfigurationPropertyNameException.class)
.isThrownBy(() -> ConfigurationPropertyName.of("foo..bar"))
.withMessageContaining("is not valid");
assertThatExceptionOfType(InvalidConfigurationPropertyNameException.class)
.isThrownBy(() -> ConfigurationPropertyName.of("foo...bar"))
.withMessageContaining("is not valid");
}

@Test
void ofNameShouldNotContainUppercase() {
assertThatExceptionOfType(InvalidConfigurationPropertyNameException.class)
Expand Down Expand Up @@ -757,6 +773,8 @@ void isValidWhenNotValidShouldReturnFalse() {
assertThat(ConfigurationPropertyName.isValid("-foo")).isFalse();
assertThat(ConfigurationPropertyName.isValid("FooBar")).isFalse();
assertThat(ConfigurationPropertyName.isValid("foo!bar")).isFalse();
assertThat(ConfigurationPropertyName.isValid("foo..bar")).isFalse();
assertThat(ConfigurationPropertyName.isValid("foo...bar")).isFalse();
assertThat(ConfigurationPropertyName.isValid("foo[")).isFalse();
}

Expand Down