From 98b92dc0a2f99c0ad0eca687ea8682a6dfd7f455 Mon Sep 17 00:00:00 2001 From: Chris Millar Date: Thu, 21 Apr 2022 18:58:34 -0600 Subject: [PATCH] MWPW-108710 - Handle Emdashes * Change makeRelative to swap emdashes for double hyphen. Resolves: MWPW-108710 --- scripts/scripts.js | 3 ++- test/scripts/scripts.test.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 63131a5e60..56fc8a6942 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -75,8 +75,9 @@ export async function loadBlock(block) { } export function makeRelative(href) { + const fixedHref = href.replace(/\u2013|\u2014/g, '--'); const hosts = [`${PROJECT_NAME}.hlx.page`, `${PROJECT_NAME}.hlx.live`, ...PRODUCTION_DOMAINS]; - const url = new URL(href); + const url = new URL(fixedHref); const relative = hosts.some((host) => url.hostname.includes(host)); return relative ? `${url.pathname}${url.search}${url.hash}` : href; } diff --git a/test/scripts/scripts.test.js b/test/scripts/scripts.test.js index d12d544d5c..b136539784 100644 --- a/test/scripts/scripts.test.js +++ b/test/scripts/scripts.test.js @@ -80,4 +80,10 @@ describe('Utilities', () => { expect(scripts.getMetadata('og:title')).to.equal('Milo'); expect(scripts.getMetadata('description')).to.equal('Website foundation technology.'); }); + + it('Makes relative URLs', () => { + const emdashHref = 'https://main—milo—adobecom.hlx.page/img/bg-dots.svg'; + const relativeUrl = scripts.makeRelative(emdashHref); + expect(relativeUrl).to.equal('/img/bg-dots.svg'); + }); });