-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()){ | ||
final String settingValueRaw = li.next(); | ||
final String settingValueResolved = propertyPlaceholder.replacePlaceholders(settingValueRaw, placeholderResolver); | ||
if (!settingValueRaw.equals(settingValueResolved)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: space after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's simpler to do away with this |
||
li.set(settingValueResolved); | ||
} | ||
} | ||
continue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space after
))
so)) }