Fixed error when saving unknown url in bookmark card (#11210)

no issue

- `payload.metadata` may not exist in a bookmark card because it's possible to save a mobiledoc document when the card is in it's "unable to parse url" state in the editor
- check for `payload.metadata` object before performing any url transformations to avoid invalid property access
This commit is contained in:
Rishabh Garg 2019-10-08 15:41:32 +05:30 committed by Kevin Ansfield
parent f1ef801b78
commit d9a0c8732c

View File

@ -93,13 +93,17 @@ module.exports = createCard({
},
absoluteToRelative(urlUtils, payload, options) {
payload.metadata.url = payload.metadata.url && urlUtils.absoluteToRelative(payload.metadata.url, options);
if (payload.metadata) {
payload.metadata.url = payload.metadata.url && urlUtils.absoluteToRelative(payload.metadata.url, options);
}
payload.caption = payload.caption && urlUtils.htmlAbsoluteToRelative(payload.caption, options);
return payload;
},
relativeToAbsolute(urlUtils, payload, options) {
payload.metadata.url = payload.metadata.url && urlUtils.relativeToAbsolute(payload.metadata.url, options);
if (payload.metadata) {
payload.metadata.url = payload.metadata.url && urlUtils.relativeToAbsolute(payload.metadata.url, options);
}
payload.caption = payload.caption && urlUtils.htmlRelativeToAbsolute(payload.caption, options);
return payload;
}