Skip to content

Commit

Permalink
Fix bug where using a YAML with anchors couldn't be loaded
Browse files Browse the repository at this point in the history
Closes gh-33404
  • Loading branch information
mhalbritter committed Nov 29, 2022
1 parent 2ceee78 commit b3878e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Expand Up @@ -79,7 +79,7 @@ private Yaml createYaml(LoaderOptions loaderOptions) {
}

List<Map<String, Object>> load() {
final List<Map<String, Object>> result = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
process((properties, map) -> result.add(getFlattenedMap(map)));
return result;
}
Expand Down Expand Up @@ -119,7 +119,9 @@ protected Object constructObject(Node node) {
}

private void replaceMappingNodeKeys(MappingNode node) {
node.setValue(node.getValue().stream().map(KeyScalarNode::get).toList());
List<NodeTuple> newValue = new ArrayList<>();
node.getValue().stream().map(KeyScalarNode::get).forEach(newValue::add);
node.setValue(newValue);
}

private Object constructTrackedObject(Node node, Object value) {
Expand Down
Expand Up @@ -173,6 +173,15 @@ void loadWhenRecursiveLoadsYaml() {
assertThat(loaded.get("test.b.boot")).hasToString("b");
}

@Test
void loadWhenUsingAnchors() {
Resource resource = new ClassPathResource("anchors.yml", getClass());
this.loader = new OriginTrackedYamlLoader(resource);
Map<String, Object> loaded = this.loader.load().get(0);
assertThat(loaded.get("some.path.config.key")).hasToString("value");
assertThat(loaded.get("some.anotherpath.config.key")).hasToString("value");
}

private OriginTrackedValue getValue(String name) {
if (this.result == null) {
this.result = this.loader.load();
Expand Down
@@ -0,0 +1,6 @@
some:
path: &anchor
config:
key: value
anotherpath:
<<: *anchor

0 comments on commit b3878e8

Please sign in to comment.