Skip to content

Commit

Permalink
Add quotes on composed flatten keys. (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Jul 22, 2020
1 parent b3eb149 commit f4f6525
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ private static Map<String, String> yamlInputToMap(final Map<String, Object> yaml
@SuppressWarnings("unchecked")
private static void flattenYaml(String path, Map<String, Object> source, Map<String, String> 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()) {
Expand Down Expand Up @@ -138,6 +142,17 @@ private static void flattenList(String key, List<Object> source, Map<String, Str
}
}

private static void escapeQuotes(StringBuilder b, String src) {
int cp;
for (int i = 0; i < src.length(); i += Character.charCount(cp)) {
cp = src.codePointAt(i);
if (cp == '\\' || cp == '"') {
b.append('\\');
}
b.appendCodePoint(cp);
}
}

private static void escapeCommas(StringBuilder b, String src, int escapeLevel) {
int cp;
for (int i = 0; i < src.length(); i += Character.charCount(cp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
Expand Down Expand Up @@ -96,6 +97,22 @@ void propertyNames() throws Exception {
assertEquals("TLSv1.3", config.getRawValue("quarkus.http.ssl.protocols.[1]"));
}

@Test
void quotedProperties() throws Exception {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(
new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example-quotes.yml")))
.withConverter(Users.class, 100, new UserConverter())
.build();

final List<String> 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<User> users;

Expand Down
7 changes: 7 additions & 0 deletions sources/yaml/src/test/resources/example-quotes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
quarkus:
log:
category:
"liquibase.changelog.ChangeSet":
level: INFO
"liquibase":
level: WARN

0 comments on commit f4f6525

Please sign in to comment.