Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environment variable substitutions in list setting #28106

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1216,13 +1216,12 @@ public boolean shouldRemoveMissingPlaceholder(String placeholderName) {
continue;
}
if (entry.getValue() instanceof List) {
List<String> ls = (List<String>) entry.getValue();
ListIterator<String> li = ls.listIterator();
while(li.hasNext()){
String value = li.next();
String value2 = propertyPlaceholder.replacePlaceholders(value, placeholderResolver);
if (! value.equals(value2)){
li.set(value2);
final ListIterator<String> li = ((List<String>) entry.getValue()).listIterator();
while (li.hasNext()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space after )) so )) }

final String settingValueRaw = li.next();
final String settingValueResolved = propertyPlaceholder.replacePlaceholders(settingValueRaw, placeholderResolver);
if (!settingValueRaw.equals(settingValueResolved)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space after )) so )) }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's simpler to do away with this if? If they are equal, it's okay to do the set?

li.set(settingValueResolved);
}
}
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ public void testReplacePropertiesPlaceholderSystemProperty() {
}

public void testReplacePropertiesPlaceholderSystemPropertyList() {
String value = System.getProperty("java.home");
assertFalse(value.isEmpty());
Settings settings = Settings.builder()
.put("property.placeholder", value)
.putList("setting1", "${property.placeholder}", "${property.placeholder}")
.replacePropertyPlaceholders()
final String hostname = randomAlphaOfLength(16);
final Settings settings = Settings.builder()
.putList("setting1", "${HOSTNAME}", "${HOSTNAME}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use two different placeholders here to test that that works?

.replacePropertyPlaceholders(name -> "HOSTNAME".equals(name) ? hostname : null)
.build();
assertThat(settings.getAsList("setting1"), contains(value, value));
assertThat(settings.getAsList("setting1"), contains(hostname, hostname));
}

public void testReplacePropertiesPlaceholderSystemVariablesHaveNoEffect() {
Expand Down