From 85f579b785b484651d6fb597804f160b133793b1 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 14 Jul 2021 15:53:55 +0100 Subject: [PATCH] Fixed error when entering invalid URL in canonical URL field closes https://github.com/TryGhost/Team/issues/745 - `URL()` will throw when given something it doesn't understand. As `seoURL` is just a display property it doesn't matter, we can catch the error and do nothing --- ghost/admin/app/components/gh-post-settings-menu.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/components/gh-post-settings-menu.js b/ghost/admin/app/components/gh-post-settings-menu.js index b3daba0593..1a6fdb343c 100644 --- a/ghost/admin/app/components/gh-post-settings-menu.js +++ b/ghost/admin/app/components/gh-post-settings-menu.js @@ -55,9 +55,13 @@ export default Component.extend({ const urlParts = []; if (this.post.canonicalUrl) { - const canonicalUrl = new URL(this.post.canonicalUrl); - urlParts.push(canonicalUrl.host); - urlParts.push(...canonicalUrl.pathname.split('/').reject(p => !p)); + try { + const canonicalUrl = new URL(this.post.canonicalUrl); + urlParts.push(canonicalUrl.host); + urlParts.push(...canonicalUrl.pathname.split('/').reject(p => !p)); + } catch (e) { + // no-op, invalid URL + } } else { const blogUrl = new URL(this.config.get('blogUrl')); urlParts.push(blogUrl.host);