Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Nov 11, 2020
2 parents 8f2de48 + 4a630dc commit 795100f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -507,7 +507,7 @@ private void load(PropertySourceLoader loader, String location, Profile profile,
}
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);
Expand Down Expand Up @@ -573,7 +573,7 @@ private String getLocationName(String locationReference, Resource resource) {

private Resource[] getResources(String locationReference) {
try {
if (locationReference.contains("*")) {
if (isPatternLocation(locationReference)) {
return getResourcesFromPatternLocationReference(locationReference);
}
return new Resource[] { this.resourceLoader.getResource(locationReference) };
Expand All @@ -583,6 +583,10 @@ private Resource[] getResources(String locationReference) {
}
}

private boolean isPatternLocation(String location) {
return location.contains("*");
}

private Resource[] getResourcesFromPatternLocationReference(String locationReference) throws IOException {
String directoryPath = locationReference.substring(0, locationReference.indexOf("*/"));
Resource resource = this.resourceLoader.getResource(directoryPath);
Expand Down
Expand Up @@ -1086,6 +1086,16 @@ void locationsWithWildcardDirectoriesShouldIgnoreHiddenDirectories() {
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/*/";
Expand Down

0 comments on commit 795100f

Please sign in to comment.