Skip to content

Commit

Permalink
Merge pull request #708 from WPMedia/fix-sign-images-null-handling
Browse files Browse the repository at this point in the history
Re-added null value check
  • Loading branch information
vgalatro authored May 24, 2024
2 parents b28a164 + 3e90284 commit f4e2d50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utils/resizer/src/sign-images-in-ans-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const signImagesInANSObject =
const replacements = new Set()

const stringData = JSON.stringify(data, (key, value) => {
if (value === null) {
return value
}
const { _id, type, auth, url } = value
if (!auth?.[resizerAppVersion] && type === 'image') {
replacements.add(_id || url)
Expand Down
15 changes: 15 additions & 0 deletions utils/resizer/src/sign-images-in-ans-object/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,19 @@ describe('Sign Images In ANS Object', () => {

expect(signedData).toMatchObject(data)
})

it('does not fail when null values are present', async () => {
const signIt = signImagesInANSObject(cachedCall, fetcher, 2)

const { data: signedData } = await signIt({
data: {
...data,
testKey: null,
},
})

expect(cachedCall).toHaveBeenCalledTimes(3)

expect(signedData).toMatchObject(data)
})
})

0 comments on commit f4e2d50

Please sign in to comment.