From f3a394a4e86be8c8730e24fa58c3642c12b671fd Mon Sep 17 00:00:00 2001 From: Nick Schubach Date: Mon, 1 Jul 2024 16:32:06 -0400 Subject: [PATCH 1/2] Change to format source code to handle urls better --- utils/resizer/src/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/resizer/src/index.js b/utils/resizer/src/index.js index 6088c4eb..8d5fa2d6 100644 --- a/utils/resizer/src/index.js +++ b/utils/resizer/src/index.js @@ -8,14 +8,14 @@ import signImagesInANSObject from './sign-images-in-ans-object/index.js' import { fetch as resizerFetch } from './signing-service/index.js' const formatSrc = (srcWithResizerUrl, resizedOptions) => { - return srcWithResizerUrl.concat( - '?', - new URLSearchParams({ - ...resizedOptions, - width: Math.floor(resizedOptions.width), - height: Math.floor(resizedOptions.height), - }).toString(), - ) + const { width, height, ...options } = resizedOptions + const url = new URL(srcWithResizerUrl) + Object.entries({ + ...options, + ...(width ?? { width: Math.floor(width) }), + ...(height ?? { height: Math.floor(height) }), + }).forEach(([key, value]) => url.searchParams.set(key, value)) + return url.toString() } function buildResizerURL( From 28d604e0ffe224e08ef9260de2d01aaeb572f667 Mon Sep 17 00:00:00 2001 From: Nick Schubach Date: Fri, 12 Jul 2024 11:45:52 -0400 Subject: [PATCH 2/2] fix bad truthy logic --- utils/resizer/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/resizer/src/index.js b/utils/resizer/src/index.js index 8d5fa2d6..8640dae4 100644 --- a/utils/resizer/src/index.js +++ b/utils/resizer/src/index.js @@ -12,8 +12,8 @@ const formatSrc = (srcWithResizerUrl, resizedOptions) => { const url = new URL(srcWithResizerUrl) Object.entries({ ...options, - ...(width ?? { width: Math.floor(width) }), - ...(height ?? { height: Math.floor(height) }), + ...(width && width !== '0' ? { width: Math.floor(width) } : {}), + ...(height && height !== '0' ? { height: Math.floor(height) } : {}), }).forEach(([key, value]) => url.searchParams.set(key, value)) return url.toString() }