Commit 67b548da authored by Phillip Webb's avatar Phillip Webb

Protect against infinite property include loop

Update `ConfigFileApplicationListener` to ensure that a
`spring.profiles.include` property that refers to an already processed
profile doesn't cause an infinite loop.

Closes gh-13361
parent 378c4c95
......@@ -543,6 +543,7 @@ public class ConfigFileApplicationListener
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
this.profiles.clear();
this.profiles.addAll(includeProfiles);
this.profiles.removeAll(this.processedProfiles);
this.profiles.addAll(existingProfiles);
}
......
......@@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests {
assertThat(this.environment.getProperty("value")).isNull();
}
@Test
public void includeLoop() {
// gh-13361
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.config.name=applicationloop");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.acceptsProfiles("loop")).isTrue();
}
private Condition<ConfigurableEnvironment> matchingPropertySource(
final String sourceName) {
return new Condition<ConfigurableEnvironment>(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment