Skip to content

Commit 2f6ec9b

Browse files
committed
Account for potentially nullable AttributeBindingModel.Value
With the `AttributeBindingModel.Value` now allowing null values (63e8b40), we need to account for that to prevent a null reference exception. With the `Key` setting, we assume a `Value` exists, as `Key` should always be `IsRequired`. With relationships, we do the same thing, as while relationships aren't required, we expect an empty value if no relationships are being submitted; if that isn't true, that's a sign of a model binding issue, and should result in an exception.
1 parent 63e8b40 commit 2f6ec9b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

OnTopic.Editor.AspNetCore/Controllers/EditorController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public async Task<IActionResult> Edit(
438438
SetReference(topic, attribute, attributeValue);
439439
}
440440
else if (attribute.Key is "Key") {
441-
topic.Key = attributeValue.Value.Replace(" ", "", StringComparison.Ordinal);
441+
topic.Key = attributeValue.Value!.Replace(" ", "", StringComparison.Ordinal);
442442
}
443443
else if (topic.BaseTopic is null && String.IsNullOrEmpty(attributeValue.Value)) {
444444
topic.Attributes.SetValue(attribute.Key, attribute.DefaultValue);
@@ -471,7 +471,7 @@ public async Task<IActionResult> Edit(
471471
/// Private helper function that saves relationship values to the topic.
472472
/// </summary>
473473
private void SetRelationships(Topic topic, AttributeDescriptor attribute, AttributeBindingModel attributeValue) {
474-
var relatedTopics = attributeValue.Value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
474+
var relatedTopics = attributeValue.Value!.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
475475
topic.Relationships.Clear(attribute.Key);
476476
foreach (var topicIdString in relatedTopics) {
477477
Topic? relatedTopic = GetAssociatedTopic(topicIdString);

0 commit comments

Comments
 (0)