From 0b7e09c986b7cb68e9bfebaab7673c0afcc041af Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 21 Mar 2023 00:09:33 +0530 Subject: [PATCH] Updated fallback for storing source site title refs https://github.com/TryGhost/Team/issues/2754 Previously, we didn't have any backup for storing source site title and it could have stored as empty if missing. This change ensures the source site title is stored as site host instead as fallback if not present. --- .../test/e2e-api/admin/__snapshots__/mentions.test.js.snap | 4 ++-- ghost/webmentions/lib/Mention.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/mentions.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/mentions.test.js.snap index d7be69a6e5..afa69aebcf 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/mentions.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/mentions.test.js.snap @@ -12,7 +12,7 @@ Object { "source_excerpt": null, "source_favicon": null, "source_featured_image": null, - "source_site_title": null, + "source_site_title": "source.com", "source_title": Any, "target": Any, "timestamp": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, @@ -27,7 +27,7 @@ Object { "source_excerpt": null, "source_favicon": null, "source_featured_image": null, - "source_site_title": null, + "source_site_title": "anothersource.com", "source_title": Any, "target": Any, "timestamp": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, diff --git a/ghost/webmentions/lib/Mention.js b/ghost/webmentions/lib/Mention.js index 26e5cd031c..8ab6a8ff5a 100644 --- a/ghost/webmentions/lib/Mention.js +++ b/ghost/webmentions/lib/Mention.js @@ -112,7 +112,11 @@ module.exports = class Mention { /** @type {string | null} */ const sourceExcerpt = validateString(metadata.sourceExcerpt, 2000, 'sourceExcerpt'); /** @type {string | null} */ - const sourceSiteTitle = validateString(metadata.sourceSiteTitle, 2000, 'sourceSiteTitle'); + let sourceSiteTitle = validateString(metadata.sourceSiteTitle, 2000, 'sourceSiteTitle'); + if (sourceSiteTitle === null) { + sourceSiteTitle = this.#source.host; + } + /** @type {string | null} */ const sourceAuthor = validateString(metadata.sourceAuthor, 2000, 'sourceAuthor');