Skip to content

Commit b4dda7a

Browse files
committed
fix(yaml): Preserve empty elements, increase max line length
1 parent 33226d9 commit b4dda7a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

format/yaml/src/main/java/org/spongepowered/configurate/yaml/YamlConfigurationLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public final class YamlConfigurationLoader extends AbstractConfigurationLoader<C
172172
Boolean.class, Integer.class, Long.class, BigInteger.class, Double.class, // numeric
173173
byte[].class, String.class, Date.class, java.sql.Date.class, Timestamp.class); // complex types
174174

175+
private static final int DEFAULT_LINE_LENGTH = 150;
176+
175177
/**
176178
* Creates a new {@link YamlConfigurationLoader} builder.
177179
*
@@ -328,6 +330,7 @@ private YamlConfigurationLoader(final Builder builder) {
328330
opts.setProcessComments(builder.commentsEnabled());
329331
opts.setIndentWithIndicator(true);
330332
opts.setIndicatorIndent(builder.indent());
333+
opts.setWidth(DEFAULT_LINE_LENGTH);
331334
this.defaultNodeStyle = builder.nodeStyle();
332335
this.options = opts;
333336
this.loader = new LoaderOptions()
@@ -339,7 +342,6 @@ private YamlConfigurationLoader(final Builder builder) {
339342

340343
@Override
341344
protected void loadInternal(final CommentedConfigurationNode node, final BufferedReader reader) throws ParsingException {
342-
// Match the superclass implementation, except we substitute our own scanner implementation
343345
final YamlParserComposer parser = new YamlParserComposer(new StreamReader(reader), this.loader, Yaml11Tags.REPOSITORY);
344346
parser.singleDocumentStream(node);
345347
}

format/yaml/src/main/java/org/spongepowered/configurate/yaml/YamlParserComposer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ private Scalar() {
536536
// todo: maybe throw here?
537537
tag = Yaml11Tags.STR;
538538
}
539-
head.node.raw(((Tag.Scalar<?>) tag).fromString(scalar.getValue()));
539+
if (!Yaml11Tags.NULL.equals(tag)) { // we don't want to nuke node data with null values
540+
head.node.raw(((Tag.Scalar<?>) tag).fromString(scalar.getValue()));
541+
}
540542
}
541543
self.applyComment(comments, head.node);
542544
head.node.hint(YamlConfigurationLoader.TAG, tag);

format/yaml/src/main/java/org/spongepowered/configurate/yaml/YamlVisitor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ public void enterNode(final ConfigurationNode node, final State state) throws Co
109109
state.mapKeyHolder.raw(node.key());
110110
state.mapKeyHolder.visit(this, state);
111111
}
112+
113+
// detect null value
114+
if (node.empty() && node.raw() == null) {
115+
state.emit(new ScalarEvent(
116+
this.anchor(node),
117+
null,
118+
new ImplicitTuple(true, false),
119+
"",
120+
null,
121+
null,
122+
DumperOptions.ScalarStyle.PLAIN
123+
));
124+
}
112125
}
113126

114127
@Override

0 commit comments

Comments
 (0)