Commit 4a630dc7 authored by Andy Wilkinson's avatar Andy Wilkinson

Only skip ..-prefixed locations when found via wildcard

Closes gh-23983
parent e8a1c3b9
......@@ -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);
......
......@@ -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/*/";
......
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