From d4bef93fefa81fc3d7a6f038c13593037a0722f4 Mon Sep 17 00:00:00 2001 From: Vito Galatro Date: Mon, 30 Oct 2023 15:42:07 -0400 Subject: [PATCH] THEMES-1479: updated URL parsing to use built in object. --- src/components/MetaData/index.test.tsx | 6 +++--- src/components/MetaData/promoImageHelper.ts | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/MetaData/index.test.tsx b/src/components/MetaData/index.test.tsx index eb655e38..71ce7c8c 100644 --- a/src/components/MetaData/index.test.tsx +++ b/src/components/MetaData/index.test.tsx @@ -44,7 +44,7 @@ const globalContentComplete = { }, promo_items: { basic: { - url: "awesome-url", + url: "https://awesome-url/image.jpg", alt_text: "alt text", }, }, @@ -73,7 +73,7 @@ const globalContentLeadArt = { promo_items: { lead_art: { type: "image", - url: "awesome-url", + url: "https://awesome-url/image.jpg", }, }, }; @@ -85,7 +85,7 @@ const globalContentLeadArtWithResize = { 0x0: "I0HK-BD7QKeAN9drBwVrYoryXDE=filters:format(jpg):quality(70):focal(3699x534:3709x544)/", }, type: "image", - url: "awesome-url", + url: "https://awesome-url/image.jpg", }, }, }; diff --git a/src/components/MetaData/promoImageHelper.ts b/src/components/MetaData/promoImageHelper.ts index 0ee0628c..5571e650 100644 --- a/src/components/MetaData/promoImageHelper.ts +++ b/src/components/MetaData/promoImageHelper.ts @@ -6,10 +6,9 @@ export const getImgURL = (metaValue, metaType = "og:image", globalContent, resiz // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require const Thumbor = require("thumbor-lite"); const thumbor = new Thumbor(RESIZER_SECRET_KEY, resizerURL); - const imgSrc = _url - .replace(/^http[s]?:\/\//, "") - .replace(" ", "%20") - .replace("?", "%3F"); + const imgSrc = new URL(_url) + .toString() + .replace(/^http[s]?:\/\//, ""); /* We need the focal point out of the resize options to use as a filter for the thumbor image being used here