From 2e2b371679f89f9723d8671e1d928baa38c8557b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 27 Oct 2020 22:22:59 -0700 Subject: [PATCH] Add auto-trimming support to configtree sources Update `ConfigTreePropertySource` with an option to automatically trim trailing new-line characters. Closes gh-23826 --- .../config/ConfigTreeConfigDataLoader.java | 3 +- .../boot/env/ConfigTreePropertySource.java | 51 ++++++++++++++++--- .../ConfigTreeConfigDataLoaderTests.java | 2 +- .../env/ConfigTreePropertySourceTests.java | 24 +++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java index 254a02a021..29c93da157 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLoader.java @@ -21,6 +21,7 @@ import java.nio.file.Path; import java.util.Collections; import org.springframework.boot.env.ConfigTreePropertySource; +import org.springframework.boot.env.ConfigTreePropertySource.Option; /** * {@link ConfigDataLoader} for config tree locations. @@ -37,7 +38,7 @@ public class ConfigTreeConfigDataLoader implements ConfigDataLoader imp /** * Convert file and directory names to lowercase. */ - USE_LOWERCASE_NAMES + USE_LOWERCASE_NAMES, + + /** + * Automatically attempt trim trailing new-line characters. + */ + AUTO_TRIM_TRAILING_NEW_LINE } @@ -173,17 +178,22 @@ public class ConfigTreePropertySource extends EnumerablePropertySource imp private final PropertyFileContent cachedContent; + private final boolean autoTrimTrailingNewLine; + private PropertyFile(Path path, Set