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:
Phillip Webb 2018-06-04 14:59:29 -07:00
parent 378c4c9535
commit 67b548dafb
4 changed files with 14 additions and 0 deletions

View File

@ -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);
} }

View File

@ -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>(

View File

@ -0,0 +1 @@
spring.profiles.include=loop

View File

@ -0,0 +1 @@
spring.profiles.include=loop