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
This commit is contained in:
parent
378c4c9535
commit
67b548dafb
|
@ -543,6 +543,7 @@ public class ConfigFileApplicationListener
|
||||||
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
|
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
|
||||||
this.profiles.clear();
|
this.profiles.clear();
|
||||||
this.profiles.addAll(includeProfiles);
|
this.profiles.addAll(includeProfiles);
|
||||||
|
this.profiles.removeAll(this.processedProfiles);
|
||||||
this.profiles.addAll(existingProfiles);
|
this.profiles.addAll(existingProfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests {
|
||||||
assertThat(this.environment.getProperty("value")).isNull();
|
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(
|
private Condition<ConfigurableEnvironment> matchingPropertySource(
|
||||||
final String sourceName) {
|
final String sourceName) {
|
||||||
return new Condition<ConfigurableEnvironment>(
|
return new Condition<ConfigurableEnvironment>(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
spring.profiles.include=loop
|
|
@ -0,0 +1 @@
|
||||||
|
spring.profiles.include=loop
|
Loading…
Reference in New Issue