Ghost/ghost/admin/app/transforms/facebook-url-user.js
Kevin Ansfield 8cbf2a5eea Fixed transformer error when saving invalid twitter/facebook URLs
closes https://github.com/TryGhost/Team/issues/746

- `.match()` returns `null` if there's no match which then breaks the array destructuring
2021-07-14 15:24:17 +01:00

22 lines
564 B
JavaScript

import Transform from '@ember-data/serializer/transform';
export default Transform.extend({
deserialize(serialized) {
if (serialized) {
let [, user] = serialized.match(/(\S+)/) || [];
return `https://www.facebook.com/${user}`;
}
return serialized;
},
serialize(deserialized) {
if (deserialized) {
let [, user] = deserialized.match(/(?:https:\/\/)(?:www\.)(?:facebook\.com)\/(?:#!\/)?(\w+\/?\S+)/mi) || [];
return user;
}
return deserialized;
}
});