Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quotes on composed flatten keys. #361

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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