Skip to content

Commit 4a630dc

Browse files
committed
Only skip ..-prefixed locations when found via wildcard
Closes gh-23983
1 parent e8a1c3b commit 4a630dc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private void load(PropertySourceLoader loader, String location, Profile profile,
522522
}
523523
continue;
524524
}
525-
if (resource.isFile() && hasHiddenPathElement(resource)) {
525+
if (resource.isFile() && isPatternLocation(location) && hasHiddenPathElement(resource)) {
526526
if (this.logger.isTraceEnabled()) {
527527
StringBuilder description = getDescription("Skipped location with hidden path element ",
528528
location, resource, profile);
@@ -588,7 +588,7 @@ private String getLocationName(String location, Resource resource) {
588588

589589
private Resource[] getResources(String location) {
590590
try {
591-
if (location.contains("*")) {
591+
if (isPatternLocation(location)) {
592592
return getResourcesFromPatternLocation(location);
593593
}
594594
return new Resource[] { this.resourceLoader.getResource(location) };
@@ -598,6 +598,10 @@ private Resource[] getResources(String location) {
598598
}
599599
}
600600

601+
private boolean isPatternLocation(String location) {
602+
return location.contains("*");
603+
}
604+
601605
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
602606
String directoryPath = location.substring(0, location.indexOf("*/"));
603607
Resource resource = this.resourceLoader.getResource(directoryPath);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,16 @@ void locationsWithWildcardDirectoriesShouldIgnoreHiddenDirectories() {
10911091
assertThat(this.environment.getProperty("fourth.property")).isNull();
10921092
}
10931093

1094+
@Test
1095+
void nonWildcardHiddenDirectoryLocationShouldNotBeIgnored() {
1096+
String location = "file:src/test/resources/config/..hidden/";
1097+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
1098+
"spring.config.location=" + location);
1099+
this.initializer.setSearchNames("testproperties");
1100+
this.initializer.postProcessEnvironment(this.environment, this.application);
1101+
assertThat(this.environment.getProperty("fourth.property")).isNotNull();
1102+
}
1103+
10941104
@Test
10951105
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
10961106
String location = "file:src/test/resources/config/*/";

0 commit comments

Comments
 (0)