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
This commit is contained in:
Kevin Ansfield 2021-07-14 15:53:55 +01:00
parent 8cbf2a5eea
commit 85f579b785

View File

@ -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);