Merge branch '2.4.x'

Closes gh-24652
This commit is contained in:
Scott Frederick 2021-01-05 14:05:58 -06:00
commit d0fba2473f
2 changed files with 20 additions and 9 deletions

View File

@ -19,6 +19,7 @@ package org.springframework.boot.env;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
@ -203,15 +204,16 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp
static Map<String, PropertyFile> findAll(Path sourceDirectory, Set<Option> options) {
try {
Map<String, PropertyFile> propertyFiles = new TreeMap<>();
Files.find(sourceDirectory, MAX_DEPTH, PropertyFile::isPropertyFile).forEach((path) -> {
String name = getName(sourceDirectory.relativize(path));
if (StringUtils.hasText(name)) {
if (options.contains(Option.USE_LOWERCASE_NAMES)) {
name = name.toLowerCase();
}
propertyFiles.put(name, new PropertyFile(path, options));
}
});
Files.find(sourceDirectory, MAX_DEPTH, PropertyFile::isPropertyFile, FileVisitOption.FOLLOW_LINKS)
.forEach((path) -> {
String name = getName(sourceDirectory.relativize(path));
if (StringUtils.hasText(name)) {
if (options.contains(Option.USE_LOWERCASE_NAMES)) {
name = name.toLowerCase();
}
propertyFiles.put(name, new PropertyFile(path, options));
}
});
return Collections.unmodifiableMap(propertyFiles);
}
catch (IOException ex) {

View File

@ -88,6 +88,15 @@ class ConfigTreePropertySourceTests {
assertThat(propertySource.getPropertyNames()).containsExactly("c", "fa.a", "fa.b", "fb.a", "fb.fa.a");
}
@Test
void getPropertyNamesFromNestedWithSymlinkInPathReturnsPropertyNames() throws Exception {
addNested();
Path symlinkTempDir = Files.createSymbolicLink(this.directory.resolveSibling("symlinkTempDir"), this.directory);
ConfigTreePropertySource propertySource = new ConfigTreePropertySource("test", symlinkTempDir);
Files.delete(symlinkTempDir);
assertThat(propertySource.getPropertyNames()).containsExactly("c", "fa.a", "fa.b", "fb.a", "fb.fa.a");
}
@Test
void getPropertyNamesFromFlatWithSymlinksIgnoresHiddenFiles() throws Exception {
ConfigTreePropertySource propertySource = getSymlinkedFlatPropertySource();