Skip to content

Commit 9de1175

Browse files
committed
Return null if applies to is empty and emit warning
1 parent b133c9d commit 9de1175

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ public class ApplicableToConverter : IYamlTypeConverter
122122

123123
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
124124
{
125+
var warnings = new List<string>();
126+
var applicableTo = new ApplicableTo();
127+
125128
if (parser.TryConsume<Scalar>(out var value))
126129
{
127130
if (string.IsNullOrWhiteSpace(value.Value))
128-
return ApplicableTo.All;
131+
{
132+
warnings.Add("The 'applies_to' field is present but empty. No applicability will be assumed.");
133+
return null;
134+
}
135+
129136
if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase))
130137
return ApplicableTo.All;
131138
}
@@ -134,10 +141,6 @@ public class ApplicableToConverter : IYamlTypeConverter
134141
if (deserialized is not Dictionary<object, object?> { Count: > 0 } dictionary)
135142
return null;
136143

137-
138-
var applicableTo = new ApplicableTo();
139-
var warnings = new List<string>();
140-
141144
var keys = dictionary.Keys.OfType<string>().ToArray();
142145
var oldStyleKeys = keys.Where(k => k.StartsWith(':')).ToList();
143146
if (oldStyleKeys.Count > 0)

0 commit comments

Comments
 (0)