dataverse-ify
dataverse-ify copied to clipboard
Missing null check in `sdkifyField`
The sdkifyField is not checking for null value before parsing to correct attribute type.
https://github.com/scottdurow/dataverse-ify/blob/0c8321d10b69556b2941aa2f330611ff67b020b6/src/dataverse-ify/sdkify/sdkify.ts#L211-L234
For example, an attribute is of type datetime and entityRecord[attributeLogicalName] is null (line 228), parsing null value to a Date object will returns an invalid Date object.
I think we can check for undefined or null before parsing like this:
if (entityRecord[attributeLogicalName] === undefined || entityRecord[attributeLogicalName] === null){
attributeValue = entityRecord[attributeLogicalName]
} else {
switch (attributeType) {
case AttributeTypes.EntityReference:
({ attributeValue, attributeLogicalName } = getEntityReference(entityRecord, field));
break;
case AttributeTypes.Money:
attributeValue = entityRecord[attributeLogicalName] as number;
break;
case AttributeTypes.MultiSelectOptionSetValue:
attributeValue = getMultiSelectOptionSet(entityRecord, attributeLogicalName);
break;
case AttributeTypes.OptionSetValue:
attributeValue = entityRecord[attributeLogicalName];
break;
case AttributeTypes.EntityCollection:
({ attributeValue, isActivityPartiesField } = await getEntityCollection(field, entityMetadata, entityRecord));
break;
case AttributeTypes.DateTime:
attributeValue = new Date(Date.parse(entityRecord[attributeLogicalName] as string));
break;
default:
// Default - set primitive type value
attributeValue = entityRecord[attributeLogicalName];
break;
}
}
entityRecord[attributeLogicalName] = attributeValue;