Skip to content

Commit

Permalink
ISPN-14226 Respect Yaml line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant committed Oct 14, 2022
1 parent e543efd commit 43e871c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ private void loadTree() {
// Child of the current node
if (parsed.listItem && parsed.name != null) {
current = addListItem(parsed, current);
} else if (!parsed.listItem && parsed.name == null) {
// It's a value continuation, append it to the current
current.parsed.value = current.parsed.value + " " + parsed.value;
continue;
}
current = current.addChild(new Node(parsed));
} else {
Expand All @@ -161,7 +165,7 @@ private void loadTree() {
current = current.addChild(new Node(parsed));
}
}
} while (parsed != null);
} while (true);
}

private Node addListItem(Parsed parsed, Node current) {
Expand Down Expand Up @@ -311,8 +315,8 @@ Parsed parseLine(final String s) {
parsed.name = null;
}
} else {
// Unterminated
throw new ConfigurationReaderException("Incomplete line", Location.of(row, 1));
// It's probably a continuation of the previous line
parsed.value = s.substring(start).trim();
}
} else if (state == 3) { // we reached the end of the line
String val = s.substring(start).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public void testYamlFile() throws IOException {
yaml.require(ConfigurationReader.ElementType.START_DOCUMENT);
yaml.nextElement();
yaml.require(ConfigurationReader.ElementType.START_ELEMENT, DEFAULT_NAMESPACE, "item1");
assertEquals(2, yaml.getAttributeCount());
assertEquals(3, yaml.getAttributeCount());
assertAttribute(yaml, "item5", "v5");
assertAttribute(yaml, "item6", "v6");
assertAttribute(yaml, "item10", "some idiot thought this was a good idea");
yaml.nextElement();
yaml.require(ConfigurationReader.ElementType.START_ELEMENT, DEFAULT_NAMESPACE, "item2");
assertEquals(4, yaml.getAttributeCount());
Expand Down
3 changes: 3 additions & 0 deletions commons/all/src/test/resources/yaml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ item1:
- 2
- 3
c: ~
item10: some idiot
thought this
was a good idea

0 comments on commit 43e871c

Please sign in to comment.