Only skip ..-prefixed locations when found via wildcard
Closes gh-23983
This commit is contained in:
parent
e8a1c3b9f8
commit
4a630dc7a9
|
|
@ -522,7 +522,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (resource.isFile() && hasHiddenPathElement(resource)) {
|
if (resource.isFile() && isPatternLocation(location) && hasHiddenPathElement(resource)) {
|
||||||
if (this.logger.isTraceEnabled()) {
|
if (this.logger.isTraceEnabled()) {
|
||||||
StringBuilder description = getDescription("Skipped location with hidden path element ",
|
StringBuilder description = getDescription("Skipped location with hidden path element ",
|
||||||
location, resource, profile);
|
location, resource, profile);
|
||||||
|
|
@ -588,7 +588,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
||||||
|
|
||||||
private Resource[] getResources(String location) {
|
private Resource[] getResources(String location) {
|
||||||
try {
|
try {
|
||||||
if (location.contains("*")) {
|
if (isPatternLocation(location)) {
|
||||||
return getResourcesFromPatternLocation(location);
|
return getResourcesFromPatternLocation(location);
|
||||||
}
|
}
|
||||||
return new Resource[] { this.resourceLoader.getResource(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 {
|
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
|
||||||
String directoryPath = location.substring(0, location.indexOf("*/"));
|
String directoryPath = location.substring(0, location.indexOf("*/"));
|
||||||
Resource resource = this.resourceLoader.getResource(directoryPath);
|
Resource resource = this.resourceLoader.getResource(directoryPath);
|
||||||
|
|
|
||||||
|
|
@ -1091,6 +1091,16 @@ class ConfigFileApplicationListenerTests {
|
||||||
assertThat(this.environment.getProperty("fourth.property")).isNull();
|
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
|
@Test
|
||||||
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
|
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
|
||||||
String location = "file:src/test/resources/config/*/";
|
String location = "file:src/test/resources/config/*/";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue