Skip to content

Commit

Permalink
Merge pull request #713 from WPMedia/format_src_fix
Browse files Browse the repository at this point in the history
Change to format source code to handle urls better
  • Loading branch information
nschubach authored Jul 12, 2024
2 parents aa5f916 + 28d604e commit 602cccd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions utils/resizer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '0' ? { width: Math.floor(width) } : {}),
...(height && height !== '0' ? { height: Math.floor(height) } : {}),
}).forEach(([key, value]) => url.searchParams.set(key, value))
return url.toString()
}

function buildResizerURL(
Expand Down

0 comments on commit 602cccd

Please sign in to comment.