Skip to content

Commit

Permalink
Fix declarative config env substitution by disallowing '}' in default…
Browse files Browse the repository at this point in the history
… value (#6793)
  • Loading branch information
jack-berg authored Oct 16, 2024
1 parent 8194c10 commit 537f5c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class FileConfiguration {

private static final Logger logger = Logger.getLogger(FileConfiguration.class.getName());
private static final Pattern ENV_VARIABLE_REFERENCE =
Pattern.compile("\\$\\{([a-zA-Z_][a-zA-Z0-9_]*)(:-([^\n]*))?\\}");
Pattern.compile("\\$\\{([a-zA-Z_][a-zA-Z0-9_]*)(:-([^\n}]*))?}");
private static final ComponentLoader DEFAULT_COMPONENT_LOADER =
SpiHelper.serviceComponentLoader(FileConfiguration.class.getClassLoader());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ private static java.util.stream.Stream<Arguments> envVarSubstitutionArgs() {
// Multiple environment variables referenced
Arguments.of("key1: ${STR_1}${STR_2}\n", mapOf(entry("key1", "value1value2"))),
Arguments.of("key1: ${STR_1} ${STR_2}\n", mapOf(entry("key1", "value1 value2"))),
Arguments.of(
"key1: ${STR_1} ${NOT_SET:-default} ${STR_2}\n",
mapOf(entry("key1", "value1 default value2"))),
// Undefined / empty environment variable
Arguments.of("key1: ${EMPTY_STR}\n", mapOf(entry("key1", null))),
Arguments.of("key1: ${STR_3}\n", mapOf(entry("key1", null))),
Expand Down

0 comments on commit 537f5c4

Please sign in to comment.