Skip to content

Commit

Permalink
fix(gatsby-plugin-utils): fix encoding issue for image-cdn (#36179)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
wardpeet and LekoArts committed Jul 22, 2022
1 parent fa06f1c commit b6d9784
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,42 @@ describe(`publicResolver`, () => {
expect.any(Object)
)
})

it(`should dispatch with decoded filename`, () => {
const actions = {
createJobV2: jest.fn(() => jest.fn()),
}

dispatchers.shouldDispatch.mockImplementationOnce(() => true)

const file = {
id: `1`,
mimeType: `image/jpeg`,
url: `https://example.com/my report.pdf`,
filename: `my report.pdf`,
parent: null,
children: [],
internal: {
type: `Test`,
owner: `test`,
contentDigest: `1`,
},
}
publicUrlResolver(file, actions, store)
expect(actions.createJobV2).toHaveBeenCalledWith(
expect.objectContaining({
args: {
contentDigest: `1`,
filename: expect.stringContaining(`my report.pdf`),
url: file.url,
},
inputPaths: [],
name: `FILE_CDN`,
outputDir: expect.stringContaining(
path.join(`public`, `_gatsby`, `file`)
),
}),
expect.any(Object)
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function dispatchLocalFileServiceJob(

publicUrl.unshift(`public`)
// get filename and remove querystring
const outputFilename = publicUrl.pop()?.split(`?`)[0]
const outputFilename = decodeURI(publicUrl.pop()?.split(`?`)?.[0] as string)

const httpHeaders = getRequestHeadersForUrl(url, store)

Expand Down Expand Up @@ -87,7 +87,7 @@ export function dispatchLocalImageServiceJob(
).split(`/`)
publicUrl.unshift(`public`)
// get filename and remove querystring
const outputFilename = publicUrl.pop()?.split(`?`)[0]
const outputFilename = decodeURI(publicUrl.pop()?.split(`?`)?.[0] as string)

const httpHeaders = getRequestHeadersForUrl(url, store) as
| Record<string, string>
Expand Down

0 comments on commit b6d9784

Please sign in to comment.