Ghost/ghost/admin/app/transforms/twitter-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
555 B
JavaScript

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