Only skip ..-prefixed locations when found via wildcard

Closes gh-23983
This commit is contained in:
Andy Wilkinson 2020-11-11 15:04:43 +00:00
parent e8a1c3b9f8
commit 4a630dc7a9
2 changed files with 16 additions and 2 deletions

View File

@ -522,7 +522,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
continue;
}
if (resource.isFile() && hasHiddenPathElement(resource)) {
if (resource.isFile() && isPatternLocation(location) && hasHiddenPathElement(resource)) {
if (this.logger.isTraceEnabled()) {
StringBuilder description = getDescription("Skipped location with hidden path element ",
location, resource, profile);
@ -588,7 +588,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
private Resource[] getResources(String location) {
try {
if (location.contains("*")) {
if (isPatternLocation(location)) {
return getResourcesFromPatternLocation(location);
}
return new Resource[] { this.resourceLoader.getResource(location) };
@ -598,6 +598,10 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
}
private boolean isPatternLocation(String location) {
return location.contains("*");
}
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
String directoryPath = location.substring(0, location.indexOf("*/"));
Resource resource = this.resourceLoader.getResource(directoryPath);

View File

@ -1091,6 +1091,16 @@ class ConfigFileApplicationListenerTests {
assertThat(this.environment.getProperty("fourth.property")).isNull();
}
@Test
void nonWildcardHiddenDirectoryLocationShouldNotBeIgnored() {
String location = "file:src/test/resources/config/..hidden/";
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
"spring.config.location=" + location);
this.initializer.setSearchNames("testproperties");
this.initializer.postProcessEnvironment(this.environment, this.application);
assertThat(this.environment.getProperty("fourth.property")).isNotNull();
}
@Test
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
String location = "file:src/test/resources/config/*/";