From 9e394eac22eb5422218257902c67bfc726959fe8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 3 Dec 2014 09:40:24 -0800 Subject: [PATCH] Fix YamlPropertySourceLoader flatten logic Fix YamlPropertySourceLoader to correctly flatten keys merged from different documents. Closes gh-2022 --- .../boot/env/YamlPropertySourceLoader.java | 4 ++-- .../boot/env/YamlPropertySourceLoaderTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java b/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java index 0fdd253ae1..58e8bde5f4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java @@ -78,10 +78,10 @@ public class YamlPropertySourceLoader implements PropertySourceLoader { process(new MatchCallback() { @Override public void process(Properties properties, Map map) { - result.putAll(map); + result.putAll(getFlattenedMap(map)); } }); - return getFlattenedMap(result); + return result; } } diff --git a/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java b/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java index 323a57e585..c2bf7ce3c3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java @@ -62,4 +62,17 @@ public class YamlPropertySourceLoaderTests { assertThat(source.getPropertyNames(), equalTo(expected.toArray(new String[] {}))); } + @Test + public void mergeItems() throws Exception { + StringBuilder yaml = new StringBuilder(); + yaml.append("foo:\n bar: spam\n"); + yaml.append("---\n"); + yaml.append("foo:\n baz: wham\n"); + ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes()); + PropertySource source = this.loader.load("resource", resource, null); + assertNotNull(source); + assertEquals("spam", source.getProperty("foo.bar")); + assertEquals("wham", source.getProperty("foo.baz")); + } + }