From f4f65252d7e44ee2d1acae9f094b829e86949911 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Wed, 22 Jul 2020 14:03:49 +0100 Subject: [PATCH] Add quotes on composed flatten keys. (#361) --- .../config/source/yaml/YamlConfigSource.java | 15 +++++++++++++++ .../source/yaml/YamlConfigSourceTest.java | 17 +++++++++++++++++ .../yaml/src/test/resources/example-quotes.yml | 7 +++++++ 3 files changed, 39 insertions(+) create mode 100644 sources/yaml/src/test/resources/example-quotes.yml diff --git a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java index a678f0b49..a7308e10e 100644 --- a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java +++ b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java @@ -98,6 +98,10 @@ private static Map yamlInputToMap(final Map yaml @SuppressWarnings("unchecked") private static void flattenYaml(String path, Map source, Map target) { source.forEach((key, value) -> { + if (key != null && key.indexOf('.') != -1) { + key = "\"" + key + "\""; + } + if (key != null && !key.isEmpty() && path != null && !path.isEmpty()) { key = path + "." + key; } else if (path != null && !path.isEmpty()) { @@ -138,6 +142,17 @@ private static void flattenList(String key, List source, Map propertyNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false) + .collect(toList()); + + assertTrue(propertyNames.contains("quarkus.log.category.liquibase.level")); + assertTrue(propertyNames.contains("quarkus.log.category.\"liquibase.changelog.ChangeSet\".level")); + assertNotNull(config.getRawValue("quarkus.log.category.\"liquibase.changelog.ChangeSet\".level")); + } + public static class Users { List users; diff --git a/sources/yaml/src/test/resources/example-quotes.yml b/sources/yaml/src/test/resources/example-quotes.yml new file mode 100644 index 000000000..3a44aa25b --- /dev/null +++ b/sources/yaml/src/test/resources/example-quotes.yml @@ -0,0 +1,7 @@ +quarkus: + log: + category: + "liquibase.changelog.ChangeSet": + level: INFO + "liquibase": + level: WARN